Entity-framework – How to Use Entity Framework 4 with Visual Studio 2013

entity-frameworkentity-framework-4visual studio 2010visual-studio-2013

We have recently upgraded our Visual Studio from 2010 to 2013. With it came EF 6.0, which is incompatible with the code generated from EF 4.

I need to update a table in the model with the latest version from the DB schema. When doing that, both "Update" and "Add" after deletion of the table definition do the following:

  • Remove all custom code already written for all types in the model, even if they are in separate files than the model;
  • Generate the new EF 6.0 bindings;
  • (optionally) Generate the new repository.
    Now, that's obviously not the same behavior as in EF 4, which only regenerated the repository and did not touch the custom code.

We are not using NuGet, but referencing the EF library inside the project.

I guess VS 2013 uses a different version of the code generator than VS 2010. How can we revert to the old behavior?

UPDATE:
I have tried using NuGet to download EF 4.3.1 and repeat the update model steps (also delete and then recreate), but I am still seeing the old behavior. I think there is a problem with the VS 2013 EF Code Generator.

Best Answer

For me, the following solution worked.

Double-click on your edmx file and open its properties window. Change Code Generation Strategy from T4 to Legacy Object Context. Build your solution. It may cause thousands of errors because you have redeclared functions and properties, so remove all files that weren't there before.

edmx properties window