here is model:
BaseObject - abstract
-Id: Guid (Entity Key)
NamedObject: BaseObject (TPC) - abstract
-Name: String
Parent: NamedObject (TPC)
Child: NamedObject (TPC)
After generating via EF DbContext template there is only one DbSet - BaseObjects, but must be instead Parents and Children
EntitySet property is disabled on TPC inherited entities
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Sorry for the delay. This is the designed behaviour: only ObjectSet of base type objects should be generated. To access only objects of an inherited type, you can invoke the OfType generic method on base ObjectSet, e.g.
Code: Select all
var parents = context.BaseObjects.OfType().ToList();
-
- Posts: 17
- Joined: Thu 29 Jun 2017 11:07
Re: EntitySet property is disabled on TPC inherited entities
Does it is possible to change this behaviour?
I would like to have one DbSet per Entity even if it is inherited from a base class.
I would like to have one DbSet per Entity even if it is inherited from a base class.
Re: EntitySet property is disabled on TPC inherited entities
Please choose one of available solutions:
1) talk to the inherited entities via OfType
2) set Generate Partial Class = True in the properties of your DbContext template and add DbSet per Entity manually in a partial class (to preserve it when regenerating the code):
3) modify a predefined DbContext template in the way you need
1) talk to the inherited entities via OfType
Code: Select all
context.BaseObjects.OfType(ChildObject).ToList();
Code: Select all
public virtual DbSet<ChildObject> ChildObjects { get; set; }