Upgrade from Entity Framework 5 to 6
This is my experience on how to successfully upgrade Entity Framework v5 to v6 for:
- SQL Server.
- C# and Visual Studio 2012.
- Database first.
Acronyms:
- EF5 = Entity Framework v5.
- EF6 = Entity Framework v6.
Checklist:
- EF5 is built into the core of .NET 4.5, whereas EF6 has been shifted out, and is open source.
- This means that you must add the new EF6 assemblies to all of the relevant projects in the solution, in particular the entry project.
- This means that you must remove assembly System.Entity from all projects, as this refers to EF5.
- EF5 has a single .dll "EntityFramework.dll", whereas EF6 has two .dlls:
- EntityFramework
- EntityFramework.SqlServer
- EF6 requires changes to app.config. The best way to make these changes is to right click on the Solution, select "Manage NuGet Packages for Solution", search for "EntityFramework" and install v6.1.0 of Entity Framework into all of the relevant projects, in particular the entry project. Make sure you uninstall any NuGet packages for EF5 Framework from all projects. This will automatically update your app.config files so they are correct.
- Examine all app.config files for references to EF5, and remove them.
- The namespaces have changed:
- Remove C# lines
using System.Data.EntityClient;
, which is an EF5 reference. - Add C# line
using System.Data.Entity.Core.EntityClient;
which is the correct for EF6.
- Remove C# lines
Still stuck? This checklist is a Community Wiki, feel free to edit this checklist to help other hapless souls who are still banging their heads against the brick wall that can be EF6 configuration.
Update 2016-02-15
Please explore other options before considering EF. It's 100x slower than other options, it's vastly over complicated for what it delivers, the entity GUI is full of bugs and has weird usability issues, and we are going to have to rip out all of our EF6 code and replace it with something that takes less than 5 minutes to make a query that takes 5 seconds in Dapper.
I think your problem is, that your T4 templates, which generate the entitties and the context are still in EF version 5.
First you have to delete the current code generation items, which are in the code behind of the model, namely <Modelname>.Context.tt
and <Modelname>.tt
.Next add a new EF version 6 code generator with Right click in the model designer-> Add Code Generation Item ... -> EF 6.x DbContext Generator
.