Retrieving latest associated record in LINQ? -
i have 3 entities entitya, entityb , entityc
entitya can have many entityb
entityb have 1 entityc , createddate
i want retrieve entityas latest entityb if 1 exists , associated entityc.
i'm struggling on linq (lambda or otherwise). can help?
entityas.select(a=>new entitya { entitybs=a.entitybs.orderbydescending(b=>b.createdate).take(1)});
if ef entity, might need include c, this:
entityas .include(a=>a.select(b=>b.entityc)) .select(a=>new entitya { entitybs=a.entitybs.orderbydescending(b=>b.createdate).take(1)});
Comments
Post a Comment