Identify TargetPerEntity table without join

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 24-Nov-2016 03:58:21   

I want to write a T-Sql query which queries the base table from a TargetPerEntity hierarchy and can identify the leaf type without doing a left join to the leaf tables.

Entity framework adds a column to a base table that stores the type identifier. Is LLBLGen able to similarly do this automatically?

Otherwise, what is an easy way of managing a type field such that its hidden from the client code? For example, it would be good to have the client code not need to set the column when creating an instance of a type from the hierarchy.

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 24-Nov-2016 15:48:26   

Just fetch the SuperType, you don't need joins, it is polymorphic.

Also you don't need a type field or a discriminator field. The type itself is definitive enough.

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 30-Jan-2017 20:22:59   

But surely the query does a join under the covers in order to determine the sub-type?

Walaa avatar
Walaa
Support Team
Posts: 14946
Joined: 21-Aug-2005
# Posted on: 30-Jan-2017 22:53:11   

If you fetch the SuperType, the framework will fetch the subTypes as well.

If you want to fetch one type only (a subtype), then you can only issue a fetch for the subtype Entity, and the framework will Join to the SuperType table to fetch the required data as well.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39588
Joined: 17-Aug-2003
# Posted on: 31-Jan-2017 10:07:06   

Ian wrote:

I want to write a T-Sql query which queries the base table from a TargetPerEntity hierarchy and can identify the leaf type without doing a left join to the leaf tables.

Entity framework adds a column to a base table that stores the type identifier. Is LLBLGen able to similarly do this automatically?

EF adds that column in code-first scenarios with Target-per-entity-hierarchy scenarios, so they're equivalent to discriminator columns. In target-per-entity scenarios, EF doesn't add a type column

Frans Bouma | Lead developer LLBLGen Pro