EntitySet property is disabled on TPC inherited entities

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
s_tristan
Posts: 9
Joined: Wed 06 Apr 2005 15:34

EntitySet property is disabled on TPC inherited entities

Post by s_tristan » Thu 13 Oct 2011 16:11

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

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 19 Oct 2011 11:36

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();

PixelHunter
Posts: 17
Joined: Thu 29 Jun 2017 11:07

Re: EntitySet property is disabled on TPC inherited entities

Post by PixelHunter » Sun 30 Jul 2017 17:31

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.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: EntitySet property is disabled on TPC inherited entities

Post by Shalex » Mon 31 Jul 2017 17:51

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

Post Reply