How to map m:n relationships with a descriminator column?

Posts   
 
    
Posts: 10
Joined: 06-Aug-2009
# Posted on: 07-Aug-2009 21:10:22   

I have two tables that are joined by a union table as such:

Consignee ConsigneeContactInfo ContactInfo


Id ------------ ConsigneeId ContactInfoId ---------------- Id Name

I am looking to retrieve a collection, something like a Dictionary<string, entity>

So when I try to access it I would use something like this:

Consignee.ContactInfo["DEFAULT"]

Where default is the descriminator attached to the column Name in ConsigneeContactInfo.

I am two days green into LLBLGen so I don't even know if there is something there already for this. However, my searches have yielded nothing.

So, I am hoping someone can show me how this is done or if it is even possible.

Thank you in advance!

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 07-Aug-2009 22:10:21   

Hi Josh,

You can use M:N relations at LLBLGenPro Designer. This allows you to PrefetchPath the ContactInfo entities associated with some Consignee without fetching the intermediate entities (ConsigneeContactInfo). (Some example assuming you are using Adapter TemplateSet):

// the path
IPrefetchPath2 path = new PrefetchPath2((int) EntityType.ConsigneeEntity);
path.Add(ConsigneeEntity.PrefetchPathContactInfos);

// fetch
// ...

// accessing entities
theFetchedConsignee.ContactInfos

Now, above code wont fetch the intermediate m:n records (CosigneeContactInfo) so you wont have the Name field accessible.

You also could prefetch the graph Consignee->ConsigneeContactInfo->ContactInfo:

// the path
IPrefetchPath2 path = new PrefetchPath2((int) EntityType.ConsigneeEntity);
path.Add(consigneeEntity.PrefetchPathConsigneeContactInfo)
     .SubPath.Add(ConseigneeContactInfoEntity.PrefetchPahContactInfo);

// fetch
// ...

// accessing entities
List<int> foundIndexes = theFetchedConsignee.ConsigneeContactInfo.FindMatches(
     ConsigneeContactInfoFields.Name == "DEFAULT");

if (foundIdexes.Count > 0)
{
     ContactInfo firstFoundContactInfo = theFetchedConsignee.ConsigneeContactInfo[ foundIndexes[0] ].ContactInfo;
}

Maybe that code doesn't fit exactly, but give you an idea of what you can do.

David Elizondo | LLBLGen Support Team