The problem is not with your code, the problem actually is that you are trying to regenerate your edmx
in higher version of EntityFramework
. One possibility could you might be modifying your old project of VS2010 in VS2013.
With previous version of Entity Framework a model created with the EF Designer would generate a context that derived from ObjectContext and entity classes that derived from EntityObject.
Starting with EF4.1 we recommended swapping to a code generation template that generates a context deriving from DbContext and POCO entity classes.
In Visual Studio 2012 you get DbContext code generated by default for all new models created with the EF Designer. Existing models will continue to generate ObjectContext based code unless you decide to swap to the DbContext based code generator.
Source: MSDN
Solution
Sergey Berezovskiy has described the solution as following, in THIS SO post.
You should either use None code generation strategy for your .edmx
file. Or remove MainModel.tt
and MainModel.Context.tt
templates, which generate model entities and context.
If you use Default code generation strategy, then entities and context will be generated into MainModel.Designer.cs
file. That would be standard entities, inherited from EntityObject
, context will be inherited of ObjectContext
. With Entity Framework 5
we have POCO
entities generation. And whole generation is done in T4
templates, which generate context, inherited from DbContext
, and POCO
entities without some base type (well, object only).
When you have both templates and enabled code generation in edmx designer, then two sets of entities will be generated. That's why you have names conflict.
You can find THIS SO post useful in order to clear your understanding and resolution of this issue.