❔ EF inheritance, selecting from multiple children
So I have this entity ProcessSpec, and 2 classes inherit from it. I'd like to be able to select a list of all ProcessSpecs, is this possible with EF?
I (think I) know inheritance can be done in 2 ways, 1) with a discriminator column. 2) with the abstract parent and 2 separate database tables for the children.
Is what I want to achieve possible? I currently have it set-up with a discriminator and when I try to select from all the children I get this error which I cannot find much info about.
16 Replies
show the code
For which?
the entities and the configuration
Anything else?
wait what
two contexts?
We have many contexts, 1 for each feature
I don't even know how inheriting a base context multiple times works, so sorry, I can't help you
also
if you're not planning to instantiate the base entity, make ot abstract
I may be wrong, but I don't think it would matter much. I can try to declare the inheritance classes' DbSets in the base context, I believe the result will be the same
same with all base classes
If you make the base entity abstract, EF will create a separate table for each child instead of 1 table
inheriting db context is just something I would never even consider
I wasn't part of the decision making for this project 😦
It is what it is now
not necessarily
you can configure it to use a single table
read the document on inheritance
in ef
Thank you ❤️
np
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.