I have the following tables: Animal
and ConcreteAnimal
. I use the first database approach if in this example it makes any difference. Suppose they are separate objects. Then I have 2 DBSet(s)
generated and can be separately updated either from the table. Things change when I set ConcreteAnimal
as a child Animal
in an entity constructor. The Entity Set field ConcreteAnimal
in the object designer becomes disabled and is automatically populated with the value of the set of objects of its parent class Animal
. DBSet
for is ConcreteAnimal
no longer generated in context. This means that I can no longer access the second, child table. How can I add ConcreteAnimal
to the database? Is behavior expected? If so, what is its logic?
EDIT: Ok, I tried the following code and it works.
using(var context = new MyEntities())
{
var concreteAnimal = new ConcreteAnimal
{
};
context.Animals.Add(concreteAnimal);
context.SaveChanges();
}
The magic happened, and both tables were filled with the correct data. It's good. However, this just does not look logical to me, why do we DBSet
only have a base class?
source
share