Upgrading EF 4 EDMX to EF 6

My application uses the EDMX database first 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 use my EF model because namespaces were changed in EF 6. Then I realized that the code generated by my EDMX also uses the wrong namespaces, etc. I do not use custom T4 yet.

How do I upgrade an existing EDMX to EF 6.

Thank.

+42
entity-framework entity-framework-4 entity-framework-6
Oct 21 '13 at 14:06 on
source share
3 answers
  • You delete old .tt files
  • You open edmx file in design mode (so you can see your model)
  • Right click on free space
  • Select Add Code Generation Item.
  • In the dialog box, select "EF 6.x DbContext Code Generation Item" (something like this)
  • Save edmx and all classes will be created for you, with new namespaces, etc.
+49
Oct 21 '13 at 14:36
source share

In addition to the answers given here by Rand Random and Dean Oliver, let me mention the following MSDN link describing the general steps for upgrading to EF6. Do not underestimate the required management steps ...

Roadmap (see details in the link above):

  • Preparation: Install Entity Framework 6 Tools for Visual Studio 2012/13

  • Install the EF6 NuGet Package

  • Make sure that the assembly references in System.Data.Entity.dll are deleted (Note: Installing the EF6 NuGet package should automatically remove any references to System.Data.Entity from your project for you).

  • Change your EF Designer (EDMX) models to by generating EF 6.x code .

    Note:

    • If you receive the message β€œThe designer of the entity data model cannot display the requested file,” then click the edit link in the displayed text message β€œEntity data model Designer ... You can change ...”, which displays the tables. Select everything with Ctrl + A , then press Del , then right-click and select "Update Model From Database" and finally save with Ctrl + S. This will update the model to the latest version using the standard T4 template "EF 6.x DbContext Generator".

    • If you used ObjectContext in your project, you should consider downloading the "EF 6.x EntityObject Generator" template. Then right-click in the model designer, select "Add Code Generation Element", then select a name that you have not used yet. It will generate the correct classes, after which you must delete all the old (" *.tt ") files and related files of the generated classes (" *.cs ").

  • Update namespaces for any major EF types , i.e.

    • any type in System.Data.* moves to System.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; the class with the old name still exists and works, but now it is marked as deprecated.
    • System.Data.Objects.EntityFunctions => System.Data.Entity.DbFunctions .
      Note: This class has been renamed; the class with the old name still exists and works, but now it is marked as deprecated.
    • Spatial classes (e.g. DbGeography , DbGeometry ) have moved from
      System.Data.Spatial => System.Data.Entity.Spatial



NB:

  • More information on the available EF templates can be found here on MSDN.

  • If after upgrading to EF6.x you get a stale attribute warning, check out this article: How to get rid of a stale attribute warning?

+25
Jul 11 '14 at 12:33
source share

Like the steps suggested by Rand Random. Be sure to install the Entity Framework 6 tools for Visual Studio 2012 if you are using VS2012. download here

This ensures that the EF 6.x DbContext Generator template is displayed when the button is clicked. Step 4: Add a code generation element

+13
Nov 01 '13 at 10:50
source share



All Articles