Inheritence (TargetPerEntityHierarchy) - am I doing it wrong?

Posts   
 
    
Posts: 497
Joined: 08-Apr-2004
# Posted on: 24-Jan-2006 10:26:39   

Hi,

I finally got round to looking at the inheritance functionality, and I'm struggling to get it working. I am using TargetPerEntityHierarchy inheritance. Here's what I have:

A table, called UserOrRole_RelatedDoc. This table for reasons I don't want to get into maps users or "roles" to documents. It contains a column called UserType, which is P for a person, or R for a role.

I thought this slightly quirky table would be a good candidate for inheritance, thinking I could create a sub-type for just Documents related to users (not roles).

So, I right-clicked it and chose to "make sub-type" in LLBLGen. I then got slightly confused at the "create sub-type dialog" asking me to specify the super-type disciminator column/value, and the subtype discriminator value. Heres what I did: I set the UserType column as the discrimnator, and for the sub-entity I entered a discriminator value of "P". I am trying to tell my new sub-type table to only be interested in rows from the original table where the UserType is P, so I fugure that makes sense. However, I dont know what to set for the discriminator value for the super-type, so I entered A - what should it be?

Anyway, after all this, I GEN'd the code, and when I do a fetch to get all of my derived (sub-type) entities, it brings them all back, not just the ones that are of type "P".

Can someone help? Have I got it all wrong?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 24-Jan-2006 10:32:09   

THe supertype discriminator column value doesn't matter, it's just that it has to have a value. So if you insert an entity of that supertype, the column gets a value.

You should fetch a collection of UserRoles, which internally should append a type filter to the query and filter on "P" rows. What did you execute and what query was generated?

Frans Bouma | Lead developer LLBLGen Pro
Posts: 497
Joined: 08-Apr-2004
# Posted on: 24-Jan-2006 12:26:42   

I did it as a dynamic list. heres the code:


            System.Data.DataTable dt = new System.Data.DataTable();
            da.FetchTypedList(DAL.FactoryClasses.EntityFieldsFactory.CreateEntityFieldsObject(DAL.EntityType.AppUser_RelatedItemEntity), dt, null, true);
            return dt;

As you say, if I go down the road of entity collection, it works!


            DAL.HelperClasses.EntityCollection ec = new DAL.HelperClasses.EntityCollection(new DAL.FactoryClasses.AppUser_RelatedItemEntityFactory());
            da.FetchEntityCollection(ec, null);

So, how do I get the TypedList version to work? Or will it not work unless I go through the entityCollection functionality?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 24-Jan-2006 14:51:53   

Please check the LLBLGen Pro documentation and read the section Filtering on entity type Under "Using the generated code - Adapter/Selfservicing - Advanced filter usage"

Posts: 497
Joined: 08-Apr-2004
# Posted on: 24-Jan-2006 15:31:57   

I see - I need to use the GetEntityTypeFilter method. Thanks for the pointer.