问题
I want to have MULTILEVEL include in my linq statment, something like
var a = departments.include(u=>u.Customers)
.include(u=>u.Customers.Include(u=>u.Orders);
How should i do that?
Thanks
回答1:
You of course can use lambda expression but you must use special format:
var a = departments.Include(d => d.Customers.Select(c => c.Orders));
回答2:
This should do the trick:
departments.Include("Customers.Orders");
Obviously you can't use a lambda expression anymore.
cf. documentation here: http://msdn.microsoft.com/en-us/library/bb738708.aspx
回答3:
[Jeroenh was quicker, but lambda is ok i think...]
Shouldnt be a problem. For entity framework without proxies we use:
var a=departments.Include("Customers.Orders").Single(dept => dept.Customers.Id == id);
/Victor
回答4:
You could specify which nested objects to be retrieved when the query is being executed by using the LoadWith method.
来源:https://stackoverflow.com/questions/8742581/mutilevel-include-in-c-sharp-linq