c# - How to access child tables with Entity Framework -


i have following tables: animal , concreteanimal. going database first approach if makes difference in example. suppose separate entities. have 2 dbset(s) generated, , can update separately either of table. things change once set concreteanimal child of animal in entity designer. entity set field of concreteanimal in entity designer becomes disabled , automatically populated value of entity set of parent class animal. dbset concreteanimal not longer generated in context. means can no longer access second, child, table. how supposed add concreteanimals database? expected behavior? if yes, logic behind it?

edit: ok, tried following code , works.

using(var context = new myentities()) {     var concreteanimal = new concreteanimal         {             //setting properties here             //both animal , specific concreteanimal         };     context.animals.add(concreteanimal);     context.savechanges(); } 

magic happened, , both tables populated correct data. good. however, not logical me why have dbset base class only?

you using tpt inheritance.

common information saved in animal table , specific information type in own table.

you find information looking in these articles:

edit

why have dbset base class only

it's question, cannot give exact answer opinion not implemented default because it's not necessary , confusing.

just imagine complex tpt scenario lot of inheritance, have 1 dbset every concrete class (which hundred of additional dbset), have ask yourself, dbset have retrieve, add or remove concrete type.

you can add code once it's generated (in partial class) , it's work.

public dbset<concreteanimal> concreteanimals { get; set; } 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -