我有一个 wpf 项目 4.5,我正在使用 EF 5 来生成模型类。我想为 EF 类实现 iNotifyPropertyChanged。所以我右键单击我的设计器(visual studio 2012)并将代码生成设置从“无”更改为“默认”
一旦我这样做了,我就会收到数百个错误,如下所示:
Error 67 'Public Property "TableColumnName" As "ColumnType" has multiple definitions with identical signatures.
[编辑 1]
这些错误都在 DataModel.Designer.Vb 文件中抛出。它们出现在与另一个表中的列/导航属性同名的任何表列属性或导航属性上。我发现很难相信我不能在不同的表中有相同名称的列,这里肯定有其他事情发生。
[编辑 2]
所以我从设计器中删除了我所有的数据库对象,然后将代码生成策略更改为默认,然后在图表中添加了一个表(客户端)。对于表的每个属性,我都收到了很多错误(所以这一定不是因为其他表的列名与我之前认为的相同)。我在上面列出的每个属性(表列)上出现错误,以及每个属性的以下错误:
Error variable '_ColumnName' conflicts with a member implicitly declared for property 'ColumnName' in class 'client'. C:...\FTC_DAL.Designer.vb
当我将代码生成返回到无时,这种情况就会消失。我开始认为这是 EF 5 中的错误。
[编辑 3]
重现步骤:
它可以是 vb 或 c,我都测试了
我在用:
我将安装 sql server 2012 express 看看这是否有什么不同
有人可以帮我弄清楚为什么会发生这些错误。
谢谢
最佳答案
请引用以下链接。我花了很多时间对这个问题感到沮丧,并从显示在“添加域服务类”屏幕上的链接中找到了这篇支持文章,该链接紧跟在“某些...可能丢失”之后...
观察的总结是 WCF RIA 不支持 DBContext(由 .tt 文件指示)。要使用域服务类,需要 ObjectContext 类。这是来自 support article 的决议.
In order to utilize your Entity Framework model with WCF RIA Services, you must convert it to an 'ObjectContext' based model. This can be done using the following steps:
- Open your entity model in the designer
- (If needed, click in the "white space" of the designer to ensure no objects within the model are selected)
- In the Properties window, change the "Code Generation Strategy" from "None" to "Default"
- Delete the two ".tt" files that are adjacent to the model, with the assumption that you have not modified these files beyond their original state when the entity model was created. If you have modified these files, then customizations to your entity model will be lost.
- Rebuild the project
After following those steps, you will be able to select your entity model's context class in the 'Available context classes' list. The side-effect of this procedure is that you have now converted your entity model from an Entity Framework DbContext-based model to an ObjectContext-based model.
关于.net - 在 Entity Framework 5 中将代码生成从无更改为默认值后出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14865038/