【问题标题】:EntityFramework 4 upgraded to 5, lambda is not availableEntityFramework 4 升级到 5,lambda 不可用
【发布时间】:2013-01-25 08:39:08
【问题描述】:

我已将“实体框架 4”项目升级到 5。我想在 Include(我的动机是取代字符串定义)括号中使用 lambda 表达式。

此时我有:

context.WarrantyContract.Include("Car");

并想实现这一点:

context.WarrantyContract.Include(w => w.Car);

但是当我尝试替换字符串时,Visual Studio 无法识别我的意愿。

我会很感激任何正确的方向。

【问题讨论】:

  • 你的WarrantyContract属性是什么类型的?
  • ObjectSet 括号中的 this 继承自 EnityObject

标签: entity-framework-5


【解决方案1】:

lambda version of the IncludeSystem.Data.Entity.DbExtensions 类中声明为extension method

为了使用它,您需要在文件中添加一个带有正确命名空间的using

using System.Data.Entity;

//...

context.WarrantyContract.Include(w => w.Car);

【讨论】:

  • 足以添加命名空间using System.Data.Entity;。 @nemesv 感谢您的快速帮助
猜你喜欢
  • 2012-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多