【问题标题】:ADO.NET Self-Tracking Entity Generator compile errorsADO.NET 自跟踪实体生成器编译错误
【发布时间】:2011-05-12 18:05:57
【问题描述】:

我不明白为什么我突然得到这些编译错误。让我们来看看我采取的步骤:

1) 我使用 Razor 视图引擎创建了一个新的 MVC3 ASP.NET 项目 (C#)

2) 在我的 Models 文件夹中,我添加了一个 ADO.NET 实体数据模型,将其连接到我的数据库,并将其命名为 Database.edmx

3) 我打开我的 Database.edmx 并选择添加代码生成项。然后我添加一个 Selft-Tracking Entity Generator 并将其命名为 Model.tt

一切都是自动生成的。然而,当我点击构建时,我得到以下编译错误:

Error   1   Cannot implicitly convert type 'System.Type' to 'MyOwnProject.Models.Type'  
Error   2   'MyOwnProject.Models.Type' does not contain a definition for 'IsValueType' and no extension method 'IsValueType' accepting a first argument of type 'MyOwnProject.Models.Type' could be found (are you missing a using directive or an assembly reference?) 
Error   3   'MyOwnProject.Models.Type' does not contain a definition for 'IsGenericType' and no extension method 'IsGenericType' accepting a first argument of type 'MyOwnProject.Models.Type' could be found (are you missing a using directive or an assembly reference?) 
Error   4   'MyOwnProject.Models.Type' does not contain a definition for 'GetGenericTypeDefinition' and no extension method 'GetGenericTypeDefinition' accepting a first argument of type 'MyOwnProject.Models.Type' could be found (are you missing a using directive or an assembly reference?)   
Error   5   Cannot implicitly convert type 'System.Type' to 'MyOwnProject.Models.Type'  
Error   6   'MyOwnProject.Models.Type' does not contain a definition for 'FullName' and no extension method 'FullName' accepting a first argument of type 'MyOwnProject.Models.Type' could be found (are you missing a using directive or an assembly reference?)   
Error   7   'MyOwnProject.Models.Type' does not contain a definition for 'FullName' and no extension method 'FullName' accepting a first argument of type 'MyOwnProject.Models.Type' could be found (are you missing a using directive or an assembly reference?)   

对我来说,这根本没有意义。我已经用这种方式创建了数据库的新项目十几次,现在,突然之间,我得到了这些编译错误。我命名数据库、edmx 或模型并没有什么区别。数据库是位于 App_Data 文件夹中还是位于我的硬盘驱动器上的外部位置也没有区别。

有人知道为什么会失败吗?谢谢。

【问题讨论】:

    标签: c# entity-framework asp.net-mvc-3 ado.net


    【解决方案1】:

    您的数据库中似乎有一个表TYPES,它生成了一个实体类Type。这个类隐藏了类System.Type。将您的实体名称更改为其他名称,例如TypeEntity.

    【讨论】:

    • 确实,我的数据库里有一个表Type……没想到。谢谢!
    • 我刚刚遇到了一个名为“EntityType”的表的问题,导致了同样的问题。我刚刚将 DataModel.Context.tt 文件中提到的“EntityType”编辑为“System.Data.Metadata.Edm.EntityType”而不是修复它。
    【解决方案2】:

    不要称您的实体为“类型”。 .NET 中有一个非常非常重要的类型,已经称为Type。你只会用这个名字给自己带来痛苦。选择一个与内置的基本类型名称不同的名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多