views:

61

answers:

0

Hi

I have these 2 entties in my edm:

Parnter members: int id, string firstname, string lastname, Partner_Address partneradress

Partner_Address members: int id, int partnerid, date validfrom

If i use create my query like this: ObjectQuery.include("Partner_Address") i get a Partner entity and could access Partner_Adress properties (eg. Partner.Partner_Adress.ValidFrom). How could achieve the same using joins / groupjoins? I've tried the following:

var inner = Query.Select(p => p.Partner_Adresse.GroupBy(pa => pa.PartnerID).Select(grp => grp.OrderByDescending(pp => pp.GueltigAb).FirstOrDefault()));

Query.GroupJoin(inner, p => p.ID, pp => pp.pa.PartnerID, (p, pp) => new {p, pp}).AsEnumerable().Select(r => r.p).ToList(); 

The output sql is correct but i can't access the sub properties of Partner_Adress like before because it's "not loaded".