简体   繁体   English

识别实体框架的版本

[英]Identifying the version of Entity Framework

One of our development machines is giving an error saying that DbContext does not implement IDisposable . 我们的开发机器之一出现错误,说DbContext没有实现IDisposable According to a similar SO post , this is because we are not referencing EF 5. The problem assembly has a *.edmx file built with older EF 4 constructs ( ObjectContext ). 根据类似的SO帖子所述 ,这是因为我们没有引用EF5。问题程序集具有一个*.edmx文件,该文件使用较早的EF 4构造( ObjectContext )构建。 This same assembly also has a newly added *.edmx file with the newer constructs ( DbContext ). 该同一程序集还具有一个新添加的*.edmx文件,该文件具有较新的结构( DbContext )。

A different project on a different machine also uses DbContext and works fine. 不同机器上的不同项目也使用DbContext并可以正常工作。 Said project shows the following information for EntityFramework.dll : 该项目显示有关EntityFramework.dll的以下信息:

version:  4.4.0.0
Runtime Version:  v4.0.30319

I checked the bad build machine and it also has this same version of EntityFramework.dll . 我检查了错误的构建机器,它也具有相同版本的EntityFramework.dll

Microsoft has had confusing conflicts between development and marketing version naming conventions. Microsoft在开发和市场营销版本命名约定之间存在令人困惑的冲突。 So does EF 5 mean the dll version should say 5.0? 那么EF 5是否意味着dll版本应为5.0?

In other words, am I running v4.0 on the good build machine? 换句话说,我是否在好的构建机器上运行v4.0? If so why is the build successful? 如果是这样,为什么构建成功?

The Entity Framework v5.0 dll is dependent on the .NET CLR you are targeting. Entity Framework v5.0 dll取决于您要定位的.NET CLR。 If your project is set to use the .NET 4.0 framework, the runtime version of the EntityFramework.dll will be 4.4.0.0. 如果您的项目设置为使用.NET 4.0框架,则EntityFramework.dll的运行时版本将为4.4.0.0。

If you are using Entity Framework with a CLR target of .NET 4.5, the version of the EntityFramework.dll will be 5.0. 如果您将实体框架与.NET 4.5的CLR目标一起使用,则EntityFramework.dll的版本将为5.0。

When you add EntityFramework via nuget, it will look at your project's CLR target runtime and add the appropriate EntityFramework.dll reference. 通过nuget添加EntityFramework时,它将查看项目的CLR目标运行时并添加适当的EntityFramework.dll引用。 If you later change your target, you should uninstall and reinstall the EntityFramework reference via nuget to make sure that the correct version of the runtime is referenced by your project. 如果以后更改目标,则应通过nuget卸载并重新安装EntityFramework引用,以确保项目引用了正确的运行时版本。

Reference post by Julie Lerman about the topic. 朱莉·勒曼(Julie Lerman)关于该主题的参考文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM