我不明白为什么会突然出现这些编译错误。让我们来看看我采取的步骤:
1) 我使用 Razor View 引擎创建了一个新的 MVC3 ASP.NET 项目 (C#)
2) 在我的模型文件夹中,我添加了一个 ADO.NET 实体数据模型,将它连接到我的数据库,并将其命名为 Database.edmx
3) 我打开我的 Database.edmx 并选择添加代码生成项。然后我添加一个自跟踪实体生成器并将其命名为 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 文件夹中,还是位于我硬盘驱动器上的外部位置也没有区别。
有谁知道为什么会失败?谢谢。
请您参考如下方法:
您的数据库中似乎有一个表TYPES,它生成了一个实体类Type。此类隐藏类 System.Type。将您的实体名称更改为其他名称,例如TypeEntity.
