-
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
Entity inheritance restrictions doesn't allow polymorphism through JSON #6001
Comments
Overloading some methods like:
Could help to specify the type. |
We've discussed this at length and concluded that we want to keep the current restrictions where the exact type of the entity being saved needs to be part of the model. Not doing this would make it very easy to think you have inheritance setup, but to inadvertently be just saving the base type data. Also, saving a derived type ( The workaround for your scenario would be to have the ability to get a |
I tried to use inheritance to have different representations of the same data using a text/JSON field (oversimplified version):
The context only has the Person entity:
When I try to add a Custormer or an Employee to the DbSet and call:
The exception is thrown:
To solve this, I tried to use TPH:
That forced me to use a "Discriminator" field, a new DbSet for every child (Customer and Employee) and a new repository for every child (Customer and Employee).
What is worse, I couldn't search for the parent entity anymore.
What if I need to query for any person, customer or employee, with a given name? Do I need to query twice the database?
The text was updated successfully, but these errors were encountered: