Question

I'm trying to upgrade a project from EF 4.3.1 to EF 6.0

The template uses ObjectContext and now, whenever I change the template, it's overwriting the generated code in the *.Designer.cs file with the old EF 4.3.1 namespaces, so the build breaks.

Is there any way I can stop this from happening? I can't see a *.tt file to hack around with. Regenerating the EDMX isn't really an option as there have been significant customisations to the conceptual model (I'd be at it for days!).

I've tried creating a new EDMX as a test and that exhibits the same problem. As soon as I change code generation to 'Default' for ObjectContext usage the EDMXName.Designer.cs file is written using the old namespaces.

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

This is driving me to distraction - I think I'm going to have to hack it down to EF 5.0

Was it helpful?

Solution

I have solved the problem. It is because you've upgraded to EF 6.X from EF 5.X your edmx is still on the old legacy generation strategy.

What you need:

After installing 1 of these extensions you want to backup your edmx and designer files (or use source control). Restart Visual Studio.

After restarting Visual Studio you want to go into your project and:

  1. Get into the diagram design surface
  2. Right click and select "add code generation item"
  3. Select the "EF 6.X Entity Object Generator" and call it something appropriate like "Template.tt"
  4. Let the generation occur
  5. Go back to the design surface and ensure that the Code Generation Strategy is now T4
  6. Delete the designer file created by the older legacy EF 5.X

This gives you your ObjectContext derived context as well as everything matching the newer EF 6.0 namespaces.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top