我已经看过很多关于如何克服这个问题的文章,所有这些都与CTP4有关,或者添加自己的扩展方法。
是否有官方EF4包含使用lambda表达式的方式(包括第一级关系以及第二级和更多级别),还是最终都不包括在RTM中?有一个 - 我会很高兴学习如何做到这一点,就像在现在的代码中使用lambda表达式(用#system.data.entity #system)一样。 data.linq)仍然给我:
无法将lambda表达式转换为类型'string',因为它不是代理类型 on:
var customers = from c in context.Customers.Include(c => c.Phone)解决方案
实体框架4.1的RTM版本实际上包括> code> EntityFramework.dll 文件中的扩展方法,以便通过 Include 函数加载lambda。只需将DLL包含在你的项目中,你就可以编写如下代码:
var princesses1 = context.Princesses.Include p => p.Unicorns).ToList();请记住添加一个Import / Using语句以包含 System.Data.Entity 命名空间。否则编译器找不到扩展方法。例如:
使用System.Data.Entity;看到这个 ADO.NET团队博客文章了解更多信息。
I've seen many articles about how to overcome this matter, all related to CTP4, Or adding my own extension methods.
Is there an "official" EF4 included way to use lambda expressions inside include (for both first level relations and also 2nd and more level) or is it eventually was not included in the RTM ?
It there is one - I would be glad to learn how to do it, as using lambda expression in my code now (with #system.data.entity #system.data.linq) still gives me:
Cannot convert lambda expression to type 'string' because it is not a delegate type on:
var customers = from c in context.Customers.Include(c=>c.Phone)解决方案
The RTM version of Entity Framework 4.1 actually includes extension methods in the EntityFramework.dll file, for eager loading with lambda through the Include function. Just include the DLL in your project and you should be able to write code like:
var princesses1 = context.Princesses.Include(p => p.Unicorns).ToList();Remember to add an Import/Using statement to include the System.Data.Entity namespace. Otherwise the compiler cannot find the extension methods. E.g:
using System.Data.Entity;See this ADO.NET team blog article for more information.
更多推荐
在实体框架4中使用lambda表达式
发布评论