我有下面的代码,不知道为什么会抛出这个错误。
using (var context = new EntitiesPlesk())
{
/////Some Code
}
using (var context = new EntitiesLan()) // Error Line
{
/////Some Code
}
我正在为 edmx 模型 (EntitiesLan) 使用 .sdf 数据库
文件
请帮助我应该在哪里更改以消除此错误....谢谢!
最佳答案
问题不在于您的代码,问题实际上是您正试图在更高版本的 EntityFramework
中重新生成您的 edmx
。一种可能是您在 VS2013 中修改 VS2010 的旧项目。
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.
来源:MSDN
解决方案
Sergey Berezovskiy在 THIS 中描述了如下解决方案所以发帖。
您应该为您的 .edmx
文件使用 None 代码生成策略。或者删除生成模型实体和上下文的 MainModel.tt
和 MainModel.Context.tt
模板。
如果您使用默认代码生成策略,那么实体和上下文将生成到 MainModel.Designer.cs
文件中。那将是标准实体,继承自 EntityObject
,context 将继承自 ObjectContext
。使用 Entity Framework 5
,我们可以生成 POCO
实体。整个生成是在 T4
模板中完成的,它生成上下文,从 DbContext
继承,并且 POCO
实体没有一些基本类型(好吧,只有对象).
当您在 edmx 设计器中同时拥有模板和启用代码生成时,将生成两组实体。这就是名称冲突的原因。
你可以找到THIS SO post useful order to clear your understanding and resolution of this issue.
关于c# - 以下方法或属性之间的调用不明确 : 'EntitiesLan.EntitiesLan()' and 'EntitiesLan.EntitiesLan()' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32921846/