-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Entity Inheritance #5813
Comments
@danielcirket Do you want UserViewModel to be mapped to the database? In other words, if you save a UserViewModel to the database and then later query it back, do you want it to come back as a UserViewModel object or as a User object? |
@ajcvickers, thank you for the prompt response. Just the user object mapped to the database, and to get a user object back rather than a UserViewModel. The Get/List are currently along these lines: User GetUserByName(string name);
User GetUserById(int id);
IEnumerable<User> Query(Expression<Func<User, bool> >predicate); |
Looks like a bug to me. EF seems to be looking to the underlying object type. |
@Bartmax It's not really a bug, it's something that is currently not supported. It would be easy to support it, but there are usability implications in doing so that we will discuss in triage before making a decision. |
Ok good to know then. |
Yeah I'd agree with @ajcvickers, it's not really a bug, it's how the internals work (There's a lot of stuff that happens for mapping types etc), it's just missing functionality unfortunately. You could get around this problem by having an extra layer between the data access and the front end business layer which would handle the object type translations (Things like automapper make this easier), but that just adds another layer of complexity which may not necessarily be wanted based on product/size/scale etc. |
At this stage this isn't a feature we are planning to enable. In general it seems having a View Model inherit from a Model type isn't really a common practice. Typically it would wrap the type rather than inherit. We are willing to reconsider if we see more folks want this feature. |
Actually having the viewmodel inherit from the model introduce overposting vulnerability |
I tried to use inheritance to have different representations of the same data using a text/JSON field (oversimplified version):
When the exception What if I need to query for any person, customer or employee, with a given name? |
@soycabanillas this issue is closed and your scenario appears to be unrelated to the issue being discussed here. Can you open a new issue. |
Done! #6001 |
Steps to reproduce
The issue
Can't use a subtype to save an instance of base type, can/how should this be configured, is it possible?
Further technical details
EF Core version: 1.0.0-rc2-final
Operating system: Windows 10
Visual Studio version: VS 2015 Pro
The text was updated successfully, but these errors were encountered: