在实体框架4使用包括拉姆达前pressions [英] Using Include in Entity Framework 4 with lambda expressions

查看:112
本文介绍了在实体框架4使用包括拉姆达前pressions的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到有关如何克服这个问题的文章,凡是涉及到CTP4,或添加自己的扩展方法。

I've seen many articles about how to overcome this matter, all related to CTP4, Or adding my own extension methods.

是否有一个官方EF4包含的方式来使用的lambda前pressions里面包括(为第一级关系,也是第二多的水平),或者是它最终没有被列入RTM?

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 ?

它存在的话 - 我会很高兴去学习如何做到这一点,因为现在我的code。使用lamdba前pression(以#System.Data.Entity的#将System.Data.Linq)仍给我:

It there is one - I would be glad to learn how to do it, as using lamdba expression in my code now (with #system.data.entity #system.data.linq) still gives me:

无法转换拉姆达前pression键入字符串',因为它不是委托类型
于:

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)

感谢。

推荐答案

实体框架4.1的RTM版本实际上包括的扩展方法的在 EntityFramework.dll 文件,通过包含功能。只是包括DLL在你的项目,你应该能够编写code,如:

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();

记住要添加一个导入/使用语句来包括 System.Data.Entity的命名空间。否则,编译器无法找到扩展方法。例如:

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;

请参阅此<一个href=\"http://blogs.msdn.com/b/adonet/archive/2011/01/31/using-dbcontext-in-ef-feature-ctp5-part-6-loading-related-entities.aspx\">ADO.NET团队博客文章的更多信息。

这篇关于在实体框架4使用包括拉姆达前pressions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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