[英]How do I upgrade a C# application using EntityFramework 4.0 to 4.3.1
We have an ASP.Net application which has been built using the Entity Framework 4.0 which is part of .Net 4.0. 我们有一个ASP.Net应用程序,它是使用Entity Framework 4.0构建的,它是.Net 4.0的一部分。 After reading a number of articles regarding the new features and, most importantly, the cleaner SQL generated by 4.1, 4.2 and 4.3, we decided to take the opportunity to upgrade our application to use 4.3.1.
在阅读了大量有关新功能的文章后,最重要的是,4.1,4.2和4.3生成的更清晰的SQL,我们决定借此机会升级我们的应用程序以使用4.3.1。
I used NuGet to install 4.3.1 into the application and it succeeded in installing the EntityFramework.dll; 我使用NuGet将4.3.1安装到应用程序中,并成功安装了EntityFramework.dll; it added a reference to it and, when I build, it is added to the bin folder.
它添加了对它的引用,当我构建时,它被添加到bin文件夹中。 At runtime, everything runs through fine but, looking in SQL profiler and using the Entity Framework Profiler by Hibernatine Rhinos, the SQL appears to be identical.
在运行时,一切都运行良好但是,查看SQL分析器并使用Hibernatine Rhinos的Entity Framework Profiler,SQL看起来是完全相同的。
As the only thing NuGet did was add a reference, I assume I need to do something else to force the application to use the 4.3.1 at runtime but I am unable to find out what I must do. 由于NuGet做的唯一事情就是添加一个引用,我假设我需要做一些其他事情来强制应用程序在运行时使用4.3.1,但我无法找到我必须做的事情。
I appreciate that the SQL may well be identical for the queries being run and that just looking at the generated SQL may not be show any differences but I would like to be able to confirm that the new version is really being used at runtime. 我很欣赏SQL对于正在运行的查询可能完全相同,只是查看生成的SQL可能没有显示任何差异,但我希望能够确认新版本确实在运行时使用。
Do I need to add something else to the web.config to ensure 4.3.1 is used or is what I have done enough? 我是否需要在web.config中添加其他内容以确保使用4.3.1或者我已经做得足够多了? Surely I need to change something somewhere in order to get things like System.Data.Entity to come from the new EntityFramework.dll rather than the standard .Net4.0 libraries.
当然,我需要在某处更改某些内容,以使System.Data.Entity等内容来自新的EntityFramework.dll,而不是标准的.Net4.0库。
Any help gratefully received. 任何帮助感激不尽。 Ste
STE
This is a reiteration of meetjaydeep's answer with steps. 这是对meetjaydeep的回答的重复。 Credit to him and to dpblog where I got a majority of this information from.
感谢他和dpblog ,我从中获得了大部分信息。
Install EF 4.3.1 as described here . 按照此处的说明安装EF 4.3.1。
Installing EF 4.3.1 安装EF 4.3.1
Please note that before you do the upgrade, this will temporarily break your code. 请注意,在进行升级之前,这将暂时中断您的代码。 So I suggest doing a backup before proceeding.
所以我建议在继续之前进行备份。
Upgrade EF 4.0 to EF 4.3.1 as described here (I would just skip to step 4). 按照此处的说明将EF 4.0升级到EF 4.3.1(我将跳到第4步)。
Upgrading from EF 4.0 to EF 4.3.1 从EF 4.0升级到EF 4.3.1
A word of caution - just because you installed EF 4.3.1, definitely does not mean you are finished. 需要注意的是 - 仅仅因为你安装了EF 4.3.1,绝对不是说你已经完成了。 What you just did is just give yourself the option to use new templates (from what I have seen after doing this myself).
你刚刚做的就是让自己选择使用新的模板(从我自己做过这些之后看到的)。 Now is it is time to use those new templates.
现在是时候使用这些新模板了。
Fixing Your Now Slightly Broken Code 修复你现在稍微破碎的代码
Your code won't compile now - don't despair - that's because what you just did is swap out System.Data.Objects.ObjectContext for the new and improved (well for me anyhow) System.Data.Entity.DbContext (Yaaaaay...) 你的代码现在不会编译 - 不要绝望 - 那是因为你刚刚做的是换掉System.Data.Objects.ObjectContext用于新的和改进的(对我来说无论如何)System.Data.Entity.DbContext(Yaaaaay。 ..)
It is totally worth the extra work to do in my opinion. 在我看来,完全值得做额外的工作。 EF 4.0 was too limited for what it was.
EF 4.0太有限了。 EF 4.3.1 is more flexible and I love the syntactical sugar that was provided.
EF 4.3.1更灵活,我喜欢提供的语法糖。 I am sure EF 5.0 is even nicer, but I can't make the leap right now.
我相信EF 5.0更好,但我现在无法实现飞跃。
Enjoy. 请享用。
To make EF4.3.1 avaliable, you should firstly install EF4.1 update1 and use the latest NuGet. 要使EF4.3.1可用,首先应安装EF4.1 update1并使用最新的NuGet。
EF4.0 is database first or model first, If you want to upgrade to EF4.3, the easiest way is use "Code Generator": http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-model-amp-database-first-walkthrough.aspx EF4.0是数据库优先或模型优先,如果你想升级到EF4.3,最简单的方法是使用“代码生成器”: http : //blogs.msdn.com/b/adonet/archive/2011/09/ 28 / EF-4-2-模型放大器数据库先walkthrough.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.