When I define a model in Entity Framework with Table-per-Type Inheritance, if I have a base class/table (not abstract) called person, and two sub entities and tables, adult and child, after creating a child, how would I take the same object and convert it to adult? Once converted to adult, the child record should be deleted, though the base class data in the person table should be retained.
When I define a model in Entity Framework with Table-per-Type Inheritance, if I have
Share
It is not possible. It is similar problem like here. Simply the entity exists and its type is immutable. The only way to do that is delete child entity (= records from both tables) and create a new adult entity (= new records for both tables).
This doesn’t look like scenario for inheritance at all.
Edit:
The comment about inheritance was targeted for scenario where you mentioned
Person,AdultandChildentities. Anyway once your scenario allows changing the type you should think about another solution where the part which can change will be handled by composition.For example:
Now changing a type means deleting dependent current
DataSourceFeaturesfrom the database and create a new one but original object remains the same – only relation changes.