My application is using a database first EDMX in EF 4. I would like to upgrade everything to EF 6. After getting EF 6 with NuGet I had to make a lot of changes to my classes that are using my EF model, because namespaces have been changed in EF 6. Then I realized, that the code generated by my EDMX does also use the wrong namespaces etc. I'm not using a custom T4 so far.
How would I upgrade my existing EDMX to EF 6.
Thank you.
As well as the steps Rand Random suggested. Remember to Install Entity Framework 6 Tools for Visual Studio 2012 if you are using VS2012. download here
This will ensure that EF 6.x DbContext Generator template shows when clicking Step 4: Add Code Generation Item
In addition to the answers given here by Rand Random and Dean Oliver, let me mention the following MSDN link, describing general steps for upgrading to EF6. Don't underestimate the manual steps required...
The road map is (see details in the link given above):
Preparation: Install the Entity Framework 6 Tools for Visual Studio 2012/13
Install the EF6 NuGet package
Ensure that assembly references to System.Data.Entity.dll are removed (Note: 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.
Notes:
ObjectContext
in your project, then you should consider downloading the template "EF 6.x EntityObject Generator". Then right-click in the model designer, choose "Add code generation item", then choose a name you haven't used yet. It will generate the right classes, afterwards you have to remove all old ("*.tt
") files and related generated class ("*.cs
") files.Update namespaces for any core EF types being used, i.e.
System.Data.*
is moved toSystem.Data.Entity.Core.*
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 is 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 is now marked as obsolete.
DbGeography
,DbGeometry
) have moved fromSystem.Data.Spatial
=>System.Data.Entity.Spatial
N.B.:
More information about available EF templates can be found here at MSDN.
If you're getting an obsolete attribute warning after upgrading to EF6.x, check out this SO article: How to get rid of obsolete attribute warning?