Upgrading to EF6

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.

时间: 2024-10-20 15:49:53

Upgrading to EF6的相关文章

[转]Upgrading to Async with Entity Framework, MVC, OData AsyncEntitySetController, Kendo UI, Glimpse &amp; 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 .NET community, we released v1.0 of the Generic Unit of Work and Repository Framework for four weeks and received 655 downloads and 4121 views. This po

MVC4使用EF6连接mysql数据库

1.需要安装MySql.Data.Entity.EF6,此dll可以在项目-->管理NuGet程序包里联机搜索MySql.Data.Entity.EF6并安装即可2.连接字符串需要添加providerName="Mysql.Data.MySqlClient"3. 将 <providers>     <provider invariantName="System.Data.SqlClient" type="System.Data.En

[渣译文] 使用 MVC 5 的 EF6 Code First 入门 系列:为ASP.NET MVC应用程序读取相关数据

这是微软官方教程Getting Started with Entity Framework 6 Code First using MVC 5 系列的翻译,这里是第六篇:为ASP.NET MVC应用程序读取相关数据 原文:Reading Related Data with the Entity Framework in an ASP.NET MVC Application 译文版权所有,谢绝全文转载--但您可以在您的网站上添加到该教程的链接. 在之前的教程中您已经完成了学校数据模型.在本教程中你将

EF6(CodeFirst)+Mysql开发脱坑指南

废话 话说当年,在一个春光明媚的晌午,邂逅了迷人的丁香姑娘,从此拜倒在了她的石榴裙下,至今不能自拔,这位丁香姑娘就是ORM思想. 所谓ORM思想,我的理解就是根据一定的规则,把程序中的对象和数据库中的关系数据相互映射转换.在当年之前,我用ADO.NET编写数据持久层,拼接T-Sql语句,这是一个相当繁琐的过程,而且针对不同的数据库,还要调整T-Sql语句.记得,第一个网站上线的时候,数据库改成了MySql的,为了适配MySql,我改了两天的Sql语句.现在每每想起,都不禁摇头哂笑. ORM思想如

MVC5+EF6 blog开发 遇到的各种问题(一)

由于是随笔,我遇到了就会记录,比较乱,作为自己解决问题的过程的记录 由于本人很久没玩儿web 了,对于最近这几年比较流行的mvc,mvp架构比较陌生,后来我突然意识到web是现在的趋势,所以我打算搞一个自己的blog. 本来一开始想用EF6+mysql 来做的,因为mysql 相对来说轻巧一些,不想mssql 那么臃肿,对于一个blog来说绰绰有余 EF问题,在我表设计了部分后,我准备写个测试代码来创建一个数据库 后来发现一直报错 说 .....sqlserver 未注册什么的,后来我发现编译的

如何在多模型的情况下进行EF6的结构迁移

所谓多模型就是在一个数据库中包含两个不同模型,或者换句话说就是两个不同DbContext的数据都放到同一个数据库中.这里的多模型不是指多租户的数据库(有谁知道EF很好处理多租户数据库的方案,可以联系我来分享给大家),也不支持跨模型共享数据. Julie Lerman在MSDN Magazine上发表了名为<EF6 Code First Migrations for Multiple Models>的文章来阐述了这个问题的两个可行解决办法: 1,利用EF6的一个新特性,即在DbMigration

&quot;kewastUnPackStats(): bad magic 1 (0xXXXXXXXXX, 0)&quot; in Alert Logfile After Upgrading to 11.2.0.1 (文档

 "kewastUnPackStats(): bad magic 1 (0xXXXXXXXXX, 0)" in Alert Logfile After Upgrading to 11.2.0.1 (文档 ID 1227524.1) 转到底部 In this Document Symptoms   Cause   Solution   References APPLIES TO: Oracle Database - Enterprise Edition - Version 9.2.0

ef6,mysql

闲下来,充下电,在网上找了一番,做个笔记. mysql 绿色版.懒得费事,放百度云盘了http://pan.baidu.com/s/1pJJSJwf 然后是搞ef6和mysql的依赖库 就这些,然后是一段别人写的代码. using System.Collections.Generic; using System.Data.Entity; using System.Linq; using System.Text; using MySql.Data.Entity; using System.Comp

[原创]VS2013 EF6连接MySql需要几步?

精简的美丽...... 1.安装mysql server下载地址 http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.21-winx64.zip注意:此url中除去文件名的部分是几乎所有文件下载的路径下面的文章可以借鉴 [MySQL]教你一步一步在Windows 8.1系统上配置免安装版mysql-5.6.21-winx64 2.安装MySql的VS插件(版本请下载最新版)mysql-for-visualstudio-1.2.3.msi 3.安装