In previous versions of EF the code was split between core libraries (primarily System.Data.Entity.dll) shipped as part of the .NET Framework and out-of-band (OOB) libraries (primarily EntityFramework.dll) shipped in a NuGet package. EF6 takes the code from the core libraries and incorporates it into the OOB libraries. This was necessary in order to allow EF to be made open source. The consequence of this is that applications will need to be rebuilt against the moved types.

This should be straightforward for applications that make use of DbContext as shipped in EF 4.1 and later. A little more work is required for applications that make use of ObjectContext but it still isn’t hard to do.

Here is a checklist of the things you need to do to upgrade an existing application to EF6.

Install the EF6 NuGet package

 

You need to upgrade to the new Entity Framework 6 runtime.

  1. Right-click on your project and select Manage NuGet Packages...
  2. Under the Online tab select EntityFramework and click Install
    Note: If a previous version of the EntityFramework NuGet package was installed this will upgrade it to EF6.

Alternatively, you can run the following command from Package Manager Console:

PM> Install-Package EntityFramework

Ensure that assembly references to System.Data.Entity.dll are removed

 

Installing the EF6 NuGet package should automatically remove any references to System.Data.Entity from your project for you.

Swap any EF Designer (EDMX) models to use EF 6.x code generation

 

If
you have any models created with the EF Designer, you will need to
update the code generation templates to generate EF6 compatible code.
Note: There are currently only EF 6.x DbContext Generator templates available for Visual Studio 2012 and 2013.

  1. Delete existing code-generation templates. These files will typically be named <edmx_file_name>.tt and <edmx_file_name>.Context.tt and be nested under your edmx file in Solution Explorer. You can select the templates in Solution Explorer and press the Del key to delete them.
    Note: In Web Site projects the templates will not be nested under your edmx file, but listed alongside it in Solution Explorer.
    Note: In VB.NET projects you will need to enable 'Show All Files' to be able to see the nested template files.
  2. Add
    the appropriate EF 6.x code generation template. Open your model in the
    EF Designer, right-click on the design surface and select Add Code Generation Item...

    • If you are using the DbContext API (recommended) then EF 6.x DbContext Generator will be available under the Data tab.
      Note: If you are using Visual Studio 2012, you will need to install the EF 6 Tools to have this template. See
      Get Entity Framework for details.
    • If you are using the ObjectContext API then you will need to select the Online tab and search for EF 6.x EntityObject Generator.
  3. If you applied any customizations to the code generation templates you will need to re-apply them to the updated templates.

Update namespaces for any core EF types being used

 

The
namespaces for DbContext and Code First types have not changed. This
means for many applications that use EF 4.1 or later you will not need
to change anything.

Types like ObjectContext that were previously
in System.Data.Entity.dll have been moved to new namespaces. This means
you may need to update your using or Import directives to build against EF6.

The
general rule for namespace changes is that any type in System.Data.* is
moved to System.Data.Entity.Core.*. In other words, just insert Entity.Core. after System.Data. For example:

  • System.Data.EntityException => System.Data.Entity.Core.EntityException
  • System.Data.Objects.ObjectContext => System.Data.Entity.Core.Objects.ObjectContext
  • System.Data.Objects.DataClasses.RelationshipManager => System.Data.Entity.Core.Objects.DataClasses.RelationshipManager

These types are in the Core
namespaces because they are not used directly for most DbContext-based
applications. Some types that were part of System.Data.Entity.dll are
still used commonly and directly for DbContext-based applications and so
have not been moved into the Core namespaces. These are:

  • System.Data.EntityState => System.Data.Entity.EntityState
  • System.Data.Objects.DataClasses.EdmFunctionAttribute =>System.Data.Entity.DbFunctionAttribute
    Note: This class has been renamed; a class with the old name still exists and works, but it now marked as obsolete.
  • System.Data.Objects.EntityFunctions => System.Data.Entity.DbFunctions
    Note: This class has been renamed; a class with the old name still exists and works, but it now marked as obsolete.)
  • Spatial classes (e.g. DbGeography, DbGeometry) have moved from System.Data.Spatial => System.Data.Entity.Spatial

Note:
Some types in the System.Data namespace are in System.Data.dll which is
not an EF assembly. These types have not moved and so their namespaces
remain unchanged.

Upgrading to EF6的更多相关文章

  1. 基于Entity Framework 6的框架Nido Framework

    随着 Entity Framework 最新主版本 EF6 的推出,Microsoft 对象关系映射 (ORM) 工具达到了新的专业高度,与久负盛名的 .NET ORM 工具相比已不再是门外汉. EF ...

  2. Entity Framework 6 编译出错的问题(VS2012)

    更新:其实这个问题是由于VS2012的EF代码生成模板是EF 5.x的,自然会与EF6 的runtime不兼容.起初我按照更新前的方式解决了,后来却发现会出现不止这一处命名空间发生改动而导致的问题. ...

  3. [转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse & Generic Unit of Work Repository Framework v2.0

    本文转自:http://www.tuicool.com/articles/BBVr6z Thanks to everyone for allowing us to give back to the . ...

  4. MVC5+EF6+MYSQl,使用codeFirst的数据迁移

    之前本人在用MVC4+EF5+MYSQL搭建自己的博客.地址:www.seesharply.com;遇到一个问题,就是采用ef的codefirst模式来编写程序,我们一般会在程序开发初期直接在glob ...

  5. ASP.NET MVC5+EF6+EasyUI 后台管理系统(1)-前言与目录(持续更新中...)

    开发工具:VS2015(2012以上)+SQL2008R2以上数据库  您可以有偿获取一份最新源码联系QQ:729994997 价格 666RMB  升级后界面效果如下: 任务调度系统界面 http: ...

  6. ASP.NET MVC5+EF6+EasyUI 后台管理系统(63)-Excel导入和导出-自定义表模导入

    系列目录 前言 上一节使用了LinqToExcel和CloseXML对Excel表进行导入和导出的简单操作,大家可以跳转到上一节查看: ASP.NET MVC5+EF6+EasyUI 后台管理系统(6 ...

  7. 【第三篇】ASP.NET MVC快速入门之安全策略(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  8. 【番外篇】ASP.NET MVC快速入门之免费jQuery控件库(MVC5+EF6)

    目录 [第一篇]ASP.NET MVC快速入门之数据库操作(MVC5+EF6) [第二篇]ASP.NET MVC快速入门之数据注解(MVC5+EF6) [第三篇]ASP.NET MVC快速入门之安全策 ...

  9. VS2012+EF6+Mysql配置心路历程

    为了学习ORM,选择了EntityFramework,经历了三天两夜的煎熬,N多次错误,在群里高手的帮助下,终于成功,现在将我的心路历程记录下来,一是让自己有个记录,另外就是让其它人少走些弯路. 我的 ...

随机推荐

  1. Java知识总结--数据库

    1 薪水排序后薪水排名在第3-5的员工 1)select * from(select ename,sal,rownum rn from (select ename,sal from emp_44 wh ...

  2. file_put_contents() 图片保存 函数成功之后返回值

    今天弄图片保存时,用到file_put_contents()来保存图片,运行了几次,发下一直没有数据出来,以为是这个函数没操作成功 于是查看了下这个函数的用法和返回值,发现我输出的返回都正确,后来才发 ...

  3. 学习PYTHON第一天

    需要掌握的内容 1.编程语言 2.python   .  C#   JAVA 3.python:  pypy    cpython     jpython 4.执行方式 解释器 文件执行 5.指定解释 ...

  4. 【加密】RSA加密之算法

    RSA公钥加密算法是1977年由Ron Rivest.Adi Shamirh和LenAdleman在(美国麻省理工学院)开发的. RSA算法是一种非对称密码算法,所谓非对称,就是指该算法需要一对密钥, ...

  5. 用最直白的语言告诉你,hadoop是什么?

    hadoop应历史之潮流,随着理论探索.科学技术试验的不断开展,hadoop终于2006年问世,惊天地泣鬼神! hadoop雏形开始于2002年的Apache的Nutch,Nutch是一个开源Java ...

  6. 教育O2O在学校落地,学堂在线瞄准混合式教学

    (大讲台—国内首个it在线教育混合式自适应学习平台.) 进入2015年,互联网教育圈最火的词非“教育O2O”莫属.不断刷新的融资金额和速度,不断曝光的正面和负面新闻,都让教育O2O公司赚足了眼球.然并 ...

  7. javascript高级编程笔记03(正则表达式)

    引用类型 检测数组 注:我们实际开发中经常遇到要把数组转化成以逗号隔开,我以前都是join来实现,其实又更简单的方法可以用toString方法,它会自动用逗号隔开转换成字符串,其实toString内部 ...

  8. ee_15_mvc_db_page----demo---bai

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"% ...

  9. MSTest不支持参数化测试的解决方案

    之前的项目中做单元测试一直用的是NUnit,这次做新项目,负责人要求统一用MsTest,理由是MsTest是Visual Studio内置的.用就用吧,我没什么意见.不过用了两天,我就发现一个大问题: ...

  10. CQRS学习——IOC,配置,仓储隔离以及QueryEntry[其三]

    从IoC开始说起 博主最早开始用的IoC容器叫AutoFac,那时候用它主要是为了生命周期管理——将EF上下文的生命周期限定为每请求.当然也总是每每听到IoC的好处,但是仍然不能理解其优势.最近在学习 ...