EF Code First - Include(x => x.Properties.Entity)a 1:许多关联 [英] EF Code First - Include(x => x.Properties.Entity) a 1 : Many association
问题描述
public class Person {...}
其中包含以下集合:
public class Address {...}
其中有一个关联:
public class Mailbox {...}
我想做:
PersonQuery.Include(x => x.Addresses).Include(Addresses.Mailbox)
不使用魔术字符串。我想使用lambda表达式来执行。
我知道我上面输入的内容将会编译,并会将所有符合搜索条件的人员的地址和每个地址邮箱渴望加载,但它是一个令我恼火的字符串。
如果没有字符串,我该怎么办?
谢谢Stack!
为此,您可以使用选择方法:
PersonQuery.Include(x => x.Addresses.Select(a => a.Mailbox));
Given a EF-Code First CTP5 entity layout like:
public class Person { ... }
which has a collection of:
public class Address { ... }
which has a single association of:
public class Mailbox { ... }
I want to do:
PersonQuery.Include(x => x.Addresses).Include("Addresses.Mailbox")
WITHOUT using a magic string. I want to do it using a lambda expression.
I am aware what I typed above will compile and will bring back all Persons matching the search criteria with their addresses and each addresses' mailbox eager loaded, but it's in a string which irritates me.
How do I do it without a string?
Thanks Stack!
For that you can use the Select method:
PersonQuery.Include(x => x.Addresses.Select(a => a.Mailbox));
You can find other examples in here and here.
这篇关于EF Code First - Include(x => x.Properties.Entity)a 1:许多关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!