.net 缺少实体框架 Include(lambda) 扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19124614/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 12:29:37  来源:igfitidea点击:

Missing Entity Framework Include(lambda) extension

.netentity-frameworklambda

提问by shannon

The EF OjbectSet.Include(a => a.parent)extension is unavailable. I know I could add code to mimic it, but according to EntityFramework 4 upgraded to 5, lambda is not availableit should be available. I have the using System.Data.Entity, and am upgraded to EF 5 in my main project.

EFOjbectSet.Include(a => a.parent)扩展不可用。我知道我可以添加代码来模拟它,但是根据升级到 5 的 EntityFramework 4,lambda 不可用它应该可用。我有using System.Data.Entity, 并在我的主项目中升级到 EF 5。

Looking 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)

查看 Assembly System.Data.Entity.dll, v4.0.0.0 (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Data.Entity.dll) 中的元数据

...

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

There is no declaration for the lambda variant of Include here. I've checked and the file version is 4.0.30319.17929, as per Database first generation Entity Framework 5 System.Data.Entity vs EntityFramework. The project is generating a 4.5 assembly.

此处没有对 Include 的 lambda 变体进行声明。我已经检查过,文件版本是 4.0.30319.17929,根据数据库第一代 Entity Framework 5 System.Data.Entity vs EntityFramework。该项目正在生成 4.5 程序集。

In case it's relevant, EntityFramework itself is not referenced in this assembly. It just has some data services, so it does include references to System.Data.Entity and the main data layer project.

如果相关,则此程序集中不引用 EntityFramework 本身。它只有一些数据服务,因此它确实包含对 System.Data.Entity 和主数据层项目的引用。

Any ideas?

有任何想法吗?

回答by Khan

According to MSDN, the method is defined in the EntityFrameworkassembly. (in EntityFramework.dll)

根据MSDN,该方法是在EntityFramework程序集中定义的。(在 EntityFramework.dll 中)

You'll need to add a reference to the EntityFramework.dllDLL as well.

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

Afterwards, you'll need to make sure you're referencing the namespace:

之后,您需要确保您正在引用命名空间:

using System.Data.Entity;

using System.Data.Entity;