Page 1 of 1

EntitySet property is disabled on TPC inherited entities

Posted: Thu 13 Oct 2011 16:11
by s_tristan
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

Posted: Wed 19 Oct 2011 11:36
by StanislavK
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();

Re: EntitySet property is disabled on TPC inherited entities

Posted: Sun 30 Jul 2017 17:31
by PixelHunter
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.

Re: EntitySet property is disabled on TPC inherited entities

Posted: Mon 31 Jul 2017 17:51
by Shalex
Please choose one of available solutions:

1) talk to the inherited entities via OfType

Code: Select all

        context.BaseObjects.OfType(ChildObject).ToList();
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):

Code: Select all

        public virtual DbSet<ChildObject> ChildObjects { get; set; }
3) modify a predefined DbContext template in the way you need