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

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -