缺失的Entity Framework Include(lambda)扩展

60
The EF OjbectSet.Include(a => a.parent) extension is not available. Although EntityFramework 4 upgraded to 5, lambda is not available, it should be available. To mimic it, you could add code. You have the using System.Data.Entity, and your main project is upgraded to EF 5. The metadata in Assembly System.Data.Entity.dll, v4.0.0.0 (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Data.Entity.dll) is being looked at.
...

public ObjectQuery<System.Data.Common.DbDataRecord> GroupBy(string keys, string projection, params ObjectParameter[] parameters);
public ObjectQuery<T> Include(string path);
public ObjectQuery<T> Intersect(ObjectQuery<T> query);

这里没有lambda Include的声明。我已经检查过文件版本,它是4.0.30319.17929,与Database first generation Entity Framework 5 System.Data.Entity vs EntityFramework相符。该项目正在生成一个4.5程序集。
如果相关的话,此程序集中未引用EntityFramework本身。它只有一些数据服务,因此包括对System.Data.Entity和主数据层项目的引用。
有什么想法吗?

17
你的代码文件顶部是否有 using System.Data.Entity 这行代码? - Khan
好的。我会在上面的注释中更清楚地表达。谢谢 Khan。 - shannon
如果您有类似的项目加载,能否告诉我“Include”所见到的元数据? - shannon
2
ReSharper在构建lambda include时不会自动识别需要using System.Data.Entity,必须手动添加或由其他过程添加。 - JabberwockyDecompiler
1
JabberwockyDecompiler - 你再次为我解决了难题。我太过信任Resharper,甚至没有想到我需要一个对using System.Data.Entity的引用。结果证明我确实需要它!再次感谢你的帮助 - 给你的评论点赞+1。 - jim tollan
1个回答

148
根据微软开发者网络(MSDN)上的说明,该方法定义在EntityFramework程序集中(EntityFramework.dll)。

您还需要添加对EntityFramework.dll DLL的引用。

然后,您需要确保引用了命名空间:

using System.Data.Entity;


2
哦,糟糕。 :) 谢谢。我想这可能是在升级过程中移动了位置。 - shannon
24
+1,这并没有回答我的问题,但是关于添加对 using System.Data.Entity 的引用的评论解决了我的问题!! - jim tollan
2
值得指出的是,有不同的EntityFramework DLL可用。我在引用中搜索并添加了唯一能找到的一个,即System.ServiceModel.DomainServices.EntityFramework(但它没有起作用)。最终我发现我需要安装.NET EntityFramework NuGet包。 - Ian

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接