X Already contains a definition Y with EntityFramework? (simple database)

徘徊边缘 提交于 2019-11-29 03:42:46

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.

Rajeshkumar
  1. Right Click the Entity model.
  2. Go to properties and remove the default name in the "Custom Tool".
  3. Assign the edmx in the model.tt and model.context
  4. Build and execute it you will be free from error.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!