Generated GetRelationInfoXXX() code is missing the predicate

Posts   
 
    
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 19-May-2012 00:02:40   

Using: Adapter template. LLBLGen Pro Version 2.6 Final (October 9th, 2009) .Net 3.5

I have a table called Parcel that, despite the name holds Parcel and PersonalProperty records. There is a flag field called IsRE that identifies which type of record it is.

Parcel has a m-to-n relationship with Tract. But this is split into two 1-n relationships via a mapping table called TractParcelMap.

So there is a 1-to-n relationship between Parcel and TractParcelMap and a 1-to-n relationship between Tract and TractParcelMap.

The LLBLGen code generated this method in the ParcelEntity class:


public virtual IRelationPredicateBucket GetRelationInfoTractCollectionViaTractParcelMap()
{
    IRelationPredicateBucket bucket = new RelationPredicateBucket();
    bucket.Relations.AddRange(GetRelationsForFieldOfType("TractCollectionViaTractParcelMap"));
    bucket.PredicateExpression.Add(new FieldCompareValuePredicate(ParcelFields.ParcelId, null, ComparisonOperator.Equal, this.ParcelId, "ParcelEntity__"));
    return bucket;
}


Later on, I decided to create a hierarchy of entities off of the Parcel table. The parent entity, which used to be called ParcelEntity is now called PropertyEntity. I made a new ParcelEntity class which is a sub-type of PropertyEntity which represents Properties that have the field IsRE = 1. I also made a PersonalPropertyEntityClass which is a sub-type of PropertyEntity which represents Properties that have the field IsRE = 0.

Since Tract records are only used by Parcels, not PersonalProperty, I did the tract relations with the ParcelEntity instead of the PropertyEntity.

However, when I generated the code, the new code for getting the TractCollectionViaTractParcelMap no longer specifies the predicate:


public virtual IRelationPredicateBucket GetRelationInfoTractCollectionViaTractParcelMap()
{
    IRelationPredicateBucket bucket = new RelationPredicateBucket();
    bucket.Relations.AddRange(GetRelationsForFieldOfType("TractCollectionViaTractParcelMap"));
    return bucket;
}

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-May-2012 06:27:28   

I can't reproduce it. I did this:

  1. Setup an inheritance graph DB. Employee (EmployeeId as PK, ...) |- Clerk (other fields) |- Manager (other fields)

  2. Create another table and an intermediate one.

Trade

TradeId Name

ClerkTrade

EmployeeId (FK to Clerk.EmployeeId TradeId (FK to Trade.TradeId)

  1. Create a v2.6 project and reverse engineer all those tables

  2. Create model-only relationships ClerkTrade m:1 Clerk ClerkTrade m:1 Trade Clerk m:n Trade

  3. Generate code. At this point TradeEntity.GetRelationInfoTradeCollectionViaClerkTrade looks like:

public virtual IRelationPredicateBucket GetRelationInfoTradeCollectionViaClerkTrade()
{
    IRelationPredicateBucket bucket = new RelationPredicateBucket();
    bucket.Relations.AddRange(GetRelationsForFieldOfType("TradeCollectionViaClerkTrade"));
    bucket.PredicateExpression.Add(new FieldCompareValuePredicate(ClerkFields.ClerkId, null, ComparisonOperator.Equal, this.ClerkId, "ClerkEntity__"));
    return bucket;
}

Do you have any reproducible steps about your scenario? If possible please attach your .lgp project. You can do this in a HelpDesk forum (which is private).

David Elizondo | LLBLGen Support Team
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 21-May-2012 20:12:40   

Perhaps I setup stuff incorrectly in LLBLGen. So I started over.

Here are the tables in the database: Parcel Tract TractParcelMap

Parcel 1:n TractParcelMap Tract 1:n TractParcelMap

Parcel table holds Parcel records and PersonalProperty records. The IsRE field indicates which type of record it is. IsRE = 1 is Parcel, IsRE = 0 is Personal Property.

I mapped the Parcel table to the PropertyEntity. I mapped the Tract table to the TractEntity. I mapped the TractParcelMap table to the TractParcelMapEntity.

I then created two subtypes for the PropertyEntity. I called them ParcelEntity and PersonalPropertyEntity using IsRE as the indicator field.

ParcelEntity has some fields in addition to those inherited from PropertyEntity. PersonalPropertyEntity only has fields inherited from PropertyEntity.

When I edit the PropertyEntity in LLBLGen and click the "Fields on relations" tab, this is what it says: FieldName = TractParcelMap; Relation = Property- TractParcelMap(1:n); Is Hidden = false; FieldName = TractCollectionViaTractParcelMap; Relation = Property - Tract (m:n) (via TractParcelMap); IsHidden = false;

Since only Parcels are associated with Tracts, in LLBLGen I want to remove the relations between PropertyEntity and TractParcelMapEntity and create relations between ParcelEntity and TractParcelMapEntity instead. What is the proper way to do that?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 21-May-2012 20:44:41   

LLBLGen Pro Version 2.6 Final (October 9th, 2009)

Would you please test this issue using the latest release of version 2.6

clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 21-May-2012 22:35:10   

Walaa wrote:

LLBLGen Pro Version 2.6 Final (October 9th, 2009)

Would you please test this issue using the latest release of version 2.6

That is the latest version of 2.6 that is available for download in the Customer Area of your website.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2012 07:04:02   

clint wrote:

Since only Parcels are associated with Tracts, in LLBLGen I want to remove the relations between PropertyEntity and TractParcelMapEntity and create relations between ParcelEntity and TractParcelMapEntity instead. What is the proper way to do that?

The correct way to do it is using TargetPerEntity, that is, you have a target table per each subEntity you want to map. See this for more info: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10376&StartAtMessage=0&#57987

David Elizondo | LLBLGen Support Team
clint
User
Posts: 150
Joined: 15-Nov-2005
# Posted on: 22-May-2012 17:52:00   

daelmo wrote:

clint wrote:

Since only Parcels are associated with Tracts, in LLBLGen I want to remove the relations between PropertyEntity and TractParcelMapEntity and create relations between ParcelEntity and TractParcelMapEntity instead. What is the proper way to do that?

The correct way to do it is using TargetPerEntity, that is, you have a target table per each subEntity you want to map. See this for more info: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10376&StartAtMessage=0&#57987

This quote from the thread you mentioned explains a lot:

If a subtype has a different relation, you have to define a table per entity, as the FK from the entity has to be placed in that subtype, not in the supertype (otherwise all entities inherit it). If the subtype entity is on the PK side, and you want to reference only that type from the FK side, you also need a different table for the subtype, otherwise it's not possible to determine which types to return if you fetch the related set.

In my situation, I can't change the database to use a table per entity at this time because it is being used by other programs.

However, I can actually work around my problem. Instead of getting the Tracts for a Parcel using the relation/predicate bucket returned by ParcelEntity.GetRelationInfoTractCollectionViaTractParcelMap() I can get the Tracts by getting the TractParcelMaps using the relation/predicate bucket returned by ParcelEntity.GetRelationInfoTractParcelMap(). But when I fetch, I'll use a Prefetch expression to fill in the TractEntity object for each TractParcelMapEntity. I tried that workaround and it works.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 22-May-2012 18:31:38   

Glad you found a work around. Thanks for the feedback.