How do I create PathEdge for "type" tables?

Posts   
 
    
Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 12-Mar-2013 15:13:37   

Hi,

The basic relationship is something like:

SiteUser --> Person -->> PersonPhone --> Phone

where PersonPhone has a PhoneType attribute. The SELECT I'm trying to model is:

select su.UserName, ph.DisplayPhoneNumber as PhoneNumber, fax.DisplayPhoneNumber as Fax, mobile.DisplayPhoneNumber as Mobile, p.* from SiteUser su join Person p on su.PersonId = p.PersonId left join PersonPhone ph on p.PersonId = ph.PersonId and ph.PhoneTypeId = 1001 -- Primary phone left join PersonPhone fax on p.PersonId = fax.PersonId and fax.PhoneTypeId = 1002 -- Fax left join PersonPhone mobile on p.PersonId = mobile.PersonId and mobile.PhoneTypeId = 1003 -- Mobile where p.PersonId = 1058

Note that I left Phone out of the above SELECT...it's optional in this case.

I don't need a filter example for the above (which I already have), I want to build an object graph in this case. I haven't found any PathEdge examples that allow for multiple "types" (phone numbers in this case). A single edge works fine:

var q = (from su in metaData.SiteUser where su.SiteUserId == userId select su).WithPath(new PathEdge<PersonEntity>( SiteUserEntity.PrefetchPathPerson, new PathEdge<PersonPhoneEntity>(PersonEntity.PrefetchPathPersonPhones, ph => ph.PhoneTypeId == (int)PhoneType.PrimaryPhone, new PathEdge<PersonPhoneEntity>(PersonPhoneEntity.PrefetchPathPhone)) ));

Trying to add a new edge differentiated only by the filter returns an exception.

I'm trying to build a graph with:

SiteUser Person PrimaryPhone Fax Mobile

While I could return a collection of PersonPhone objects, in this case I would like to return individual Entities. How do I add the additional PersonPhone PathEdge's that are differentiated by the filter?

Thanks!

Gabbo
User
Posts: 56
Joined: 12-Jun-2006
# Posted on: 12-Mar-2013 23:05:53   

Never mind on this one. As I thought about it and experimented it seemed pretty clear this has to be supported at the designer level (need differently named objects).

I'll either use custom objects or return the collection.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Mar-2013 07:05:23   

Exactly. To do it in a PrefetchPath fashion you need that PersonEntity has navigators: PersonalPhone, MobilePhone, etc. To do so you would need to create a TargetPerEntityHierarchy on PersonalPhone, and make the PhoneType field the discriminator value (ref...), Although I don't know if this would be a good decision (ref...).

You could just prefetch the PersonPhone and PersonPhone.Phone graph, then you could write specific Person's properties like PersonalPhone, MobilePhone, etc, that selects the appropfiate entity from PersonPhone collection and return it, based on the PhoneType.

David Elizondo | LLBLGen Support Team