.net - 在 Entity Framework 5 中将代码生成从无更改为默认值后出现错误

标签 .net visual-studio entity-framework entity-framework-5

我有一个 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]

重现步骤:
  • 在 Visual Studio 2012 中创建新项目,wpf 应用程序。
    它可以是 vb 或 c,我都测试了
  • 添加 ADO.NET 实体数据模型(edmx 文件)
  • 从 sql 服务器添加一个表(我使用的是 express 2008 R2)
  • 构建项目,然后在空白处单击 edmx 设计器。在属性窗口中,更改 代码生成策略 默认而不是无。
  • 构建项目,错误将出现。

  • 我在用:
  • Visual Studio 2012 专业版 v.11.0.51106.01 更新 1
  • .NET 4.5.50709
  • Windows 8 专业版

  • 我将安装 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:

    1. Open your entity model in the designer
    2. (If needed, click in the "white space" of the designer to ensure no objects within the model are selected)
    3. In the Properties window, change the "Code Generation Strategy" from "None" to "Default"
    4. 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.
    5. 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/

    相关文章:

    c++ - 如何在 Visual Studio 调试器中访问 IloIntArray 元素?

    c++ - 从 MFC C++ 6.0 应用程序迁移到 VS 2005

    entity-framework - 包含路径表达式必须引用在类型上定义的导航属性

    c# - 如何在 Entity Framework 中使用 Fluent API 以一对多关系映射枚举?

    c# - 有没有办法直接查询 Entity Framework Core 使用的内存数据库?

    .net - .NET应用程序-提取程序集/文件版本令人困惑

    .net - 如何判断 new-object 来自哪个版本的程序集?

    c++ - 可以在 C++ 中的字符串文字中写入 unicode 字符吗

    c# - EF6/SQL Server Compact,基于代码的配置

    c# - 在 C# 中将 OracleDataReader 导出到 Excel