EF Code First - Include(x => x.Properties.Entity) a 1 : 许多关联
给定一个 EF-Code First CTP5 实体布局,如下所示:
public class Person { ... }
它具有以下集合:
public class Address { ... }
其具有单个关联:
public class Mailbox { ... }
我想做:
PersonQuery.Include(x => x.Addresses).Include("Addresses.Mailbox")
不使用魔术字符串。我想使用 lambda 表达式来完成此操作。
我知道我上面输入的内容将进行编译,并将带回所有与搜索条件匹配的人员及其地址以及每个地址的邮箱渴望加载的内容,但它是在一个字符串中,这让我很恼火。
没有绳子怎么办?
谢谢堆栈!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为此,您可以使用Select方法:
您可以在这里和此处。
For that you can use the Select method:
You can find other examples in here and here.
对于任何仍在寻找解决方案的人来说,Lambda 包含是 EF 4+ 的一部分,并且位于 System.Data.Entity 命名空间中;这里的例子
http://romiller.com/2010/07/14 /ef-ctp4-tips-tricks-include-with-lambda/
For any one thats still looking for a solution to this, the Lambda includes is part of EF 4+ and it is in the System.Data.Entity namespace; examples here
http://romiller.com/2010/07/14/ef-ctp4-tips-tricks-include-with-lambda/
这篇文章中对此进行了描述: http://www.thomaslevesque.com/2010/10/03/entity-framework-using-include-with-lambda-expressions/
编辑(由 Asker 提高可读性):
您正在寻找的部分如下:
It is described in this post: http://www.thomaslevesque.com/2010/10/03/entity-framework-using-include-with-lambda-expressions/
Edit (By Asker for readability):
The part you are looking for is below: