andreas
andreas

Reputation: 888

How to update EDMX file version 2.0 to 3.0?

I have a VS-2012 solution using Entity Framework 5. The EDMX file is version 2.0:

<edmx:Edmx Version="2.0" xmlns:edmx="http://schemas.microsoft.com/ado/2008/10/edmx">

When I create a new project with VS and a new EDMX file it will be version 3.0. Since I have some trouble with not working features in the designer with the 2.0 version I want to migrate the EDMX file to the new version.

How do I do this?

Upvotes: 4

Views: 4498

Answers (3)

Luke Puplett
Luke Puplett

Reputation: 45095

What I ended up doing was creating a new empty, EF model; a new Test.edmx file.

Then I copied and pasted the values inside the elements that have schema attributes, from my original EDMX to the new one for example:

<edmx:StorageModels>
  <Schema xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
          Namespace="Entities.Store" Alias="Self" Provider="System.Data.SqlClient" ProviderManifestToken="2008" >
    
    ... paste contents from original EDMX ...

  </Schema>
</edmx:StorageModels>

Then I copy pasted the whole thing back over my original EDMX and deleted the test one. Obviously used source control to compare and check for mess-ups.

I needed to fix-up a few things:

  • The Namespace="Test" to whatever is was originally.
  • The ProviderManifestToken
  • Add a schema declaration for xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" when it complained of not knowing what store:Type elements were.
  • Oddly, I think it reset the Custom Tool Namespace on the EDMX so my generated classes were not in the CLR namespace I wanted and my partial class partners were 'disconnected' if you know what I mean.

Upvotes: 0

Pawel
Pawel

Reputation: 31610

If a project targets .NET Framework 4 and you are not using EF6 or newer you should not change the version of the EDMX 2.0.

  • This is because EF that shipped with .NET Framework 4 does not know how to handle v3 features like enums, spatial types etc.
  • True, that many machines these days have installed .NET Framework 4.5 or newer and it will be used to run your project even if it targets .NET Framework 4 (.NET Framework 4.5 and newer are in-place upgrades).

  • But if you change the version of EDMX and happen to run your app on a machine that has only .NET Framework 4 it will die on the spot.

If you need to move to EDMX 3 you need to retarget your project from .NET Framework 4 to .NET Framework 4.5 which will automatically upgrade the version of your EDMX. If you want to use EDMX 3 features on .NET Framework 4 the only way to do it is to use EF6 or newer. The new designer does support this scenario - you can read about this here.

Upvotes: 1

RyanB
RyanB

Reputation: 757

If you add the edmx file by adding an "existing item" and then try to open the file it should give you an error. Click "modify" and then it should open. Go to the properties (F4), change the "Code Generation Strategy" to "T4" and then save the EDMX file.

Then you can open the EDMX file with a text editor and make sure the 2nd line has edmx:Edmx Version="3.0"

Upvotes: 0

Related Questions