TargetPerEntity with discriminator column possible?

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 01-Aug-2008 19:59:30   

Hi,

the LLBLGen handbook states:

There are in general 4 ways to map entity / class hierarchies (inheritance hierarchies) onto a set of tables / views: 1) Complete hierarchy mapped onto a single table. In LLBLGen Pro this is called TargetPerEntityHierarchy. This is the inheritance type which is very easy to implement and therefore supported by most O/R mappers. 2) Every type in a hierarchy mapped onto its own table, no discriminator column. In LLBLGen Pro this is called TargetPerEntity. This inheritance type is hard to implement, most O/R mappers fall back to option 3. 3) Every type in a hierarchy mapped onto its own table, with discriminator column in root type. Similar to option 2, and because LLBLGen Pro doesn't need a discriminator column for option 2, this type is supported but the discriminator column is ignored / not required.

I have a TargetPerEntity relationship in my database and would like to set it up as 3) instead of 2).

The reason is, that it would he helpful for the reporting engine and other clients beside LLBLGen accessing the database to know what type is present.

How could I implement 3) please?

Thanks, Patrick

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Aug-2008 04:38:15   

Could you please elaborate more on how is your setup? As I see, you need TargetPerEntity, here is how you should use it at Designer, also read about polymorphic fetches. Does that fit in your scenario?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 02-Aug-2008 11:30:23   

You can have a field which is your discriminator field, but it's ignored and not designable in the designer. So to automatically set the field you want to use as discriminator field, add a partial class to the entity and override OnInitialized and set the field using this.<fieldname> = value.

Though, determining a type of entity is doable with normal .NET constructs as well.

Frans Bouma | Lead developer LLBLGen Pro
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 06-Aug-2008 03:12:18   

Otis wrote:

Though, determining a type of entity is doable with normal .NET constructs as well.

Cool than I can just override OnInitialized in the base class and it would be persisted with the entity.

Thanks, Patrick

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 06-Aug-2008 12:16:54   

Yes you can do that although you'd better handle it inside each subclass. As it is recommended that the base class should be shielded from its inheriters. Check this discussion