EF Code First - Include(x => x.Properties.Entity)a 1:许多关联 [英] EF Code First - Include(x => x.Properties.Entity) a 1 : Many association

查看:130
本文介绍了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表达式来执行。



我知道我上面输入的内容将会编译,并会将所有符合搜索条件的人员的地址和每个地址邮箱渴望加载,但它是一个令我恼火的字符串。



如果没有字符串,我该怎么办?



谢谢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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆