.net - Explicit loading of grandchild collections in EF 4.1 -


given following model ...

public class parent {     public int id { get; set; }     public icollection<child> children { get; set; } }  public class child {     public int id { get; set; }     public icollection<grandchild> grandchildren { get; set; } }  public class grandchild {     public int id { get; set; } } 

... can eager load include parent children , grandchildren in 1 step so:

context.parents.include(p => p.children.select(c => c.grandchildren)) 

is similar possible explicit loading?

the child collection can explicitely loaded way:

parent parent = context.parents.find(parentid); context.entry(parent).collection(p => p.children).load(); 

but trying load children in similar way include ...

context.entry(parent)     .collection(p => p.children.select(c => c.grandchildren)).load(); 

... doesn't compile und string overload of collection ...

context.entry(parent).collection("children.grandchildren").load(); 

... throws exception ("...no dotted paths allowed...").

the thing found working explicitely load grandchildren in loop:

parent parent = context.parents.find(parentid); context.entry(parent).collection(p => p.children).load(); foreach (var child in parent.children)     context.entry(child).collection(c => c.grandchildren).load(); 

i wondering if missed , if there other way explicitely load grandchildren in 1 roundtrip.

thanks feedback in advance!

as pointed in comment can try query relation first, add includes , execute loading. like:

context.entry(parent)        .collection(p => p.children)        .query()        .include(c => c.grandchildren) // i'm not sure if can include grandchild directly          .load(); 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -