Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

Updated Wiki: Updating Applications to use EF6

$
0
0

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.

Checklist

Here is a checklist of the things you need to do to use pre-release versions of EF6. Details for each of these steps are provided in the sections below.

  • Install the EF6 NuGet package
  • Remove assembly references to System.Data.Entity.dll
  • Update namespaces for any core EF types being used

Install the EF6 NuGet package

You can get an EF6 NuGet package in three ways:

When you build EF6 using the instructions from the documentation page one of the outputs of the build is an EF6 NuGet package. You can find it in “src\NuGet\bin\Release\EntityFramework.6.0.0-beta1.nupkg”. Using this NuGet package is the easiest way to get EF6 into your application. To do this setup a local feed based on the "bin\Release\" folder and install it in the normal way:

PM> Install-Package EntityFramework -Pre

Make sure you are installing from the local feed and using the -Pre flag since the EF6 package is currently a pre-release package. Also note that if you perform a debug build from within Visial Studio then the resulting package will be in the Debug folder and you should install it from there.

Remove assembly references to System.Data.Entity.dll

Installing the EF6 NuGet package adds the following runtime assemblies to your project:

  • EntityFramework.dll – All the common runtime code used by EF
  • EntityFramework.SqlServer.dll – The Microsoft SQL Server provider for EF

Any assembly reference to System.Data.Entity.dll should be removed. EF6 doesn’t use any code from System.Data.Entity.dll and having it referenced in your project could cause build conflicts. (These conflicts can be resolved but in general you should not be using EF6 and System.Data.Entity.dll in the same application.)

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 yourusing 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 insertEntity.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 that the class has been renamed.)
  • System.Data.Objects.EntityFunctions => System.Data.Entity.EntityFunctions
  • Spatial classes (e.g. DbGeography, DbGeometry) have moved from System.Data.Spatial => System.Data.Entity.Spatial

Note that 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.

Current limitations

There are currently certain limitations of EF6 due to its pre-release nature. These include:

  • The EntityFramework NuGet package includes a provider for SQL Server. The EF6 build also creates an EntityFramework.SqlServerCompact package containing an EF6 provider for SQL Server CE. Other providers, including wrapping providers for tracing and caching, will need to be re-built for EF6. Until this is done you will not be able to use EF6 with other types of database.
  • Some external tooling (such as MVC scaffolding) is not yet updated to work with EF6.

Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>