2011-05-12 53 views
1

我想不通为什么我突然得到这些编译错误。让我们通过我采取的步骤:使用Razor视图引擎ADO.NET自我追踪实体生成器编译错误

2)在我的模型文件夹

1)我创建了一个新的ASP.NET MVC3项目(C#),我添加一个ADO.NET实体数据型号,将其连接到我的数据库,并命名它Database.edmx

3)我打开我的Database.edmx并选择添加代码生成项目。然后添加一个Selft-Tracking实体生成器并将其称为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文件夹中或硬盘驱动器上的外部位置也无关紧要。

有没有人有任何想法,为什么这是失败?谢谢。

回答

2

看起来您的数据库中有一个表TYPES,导致实体类Type。该课程隐藏课程System.Type。将实体的名称更改为其他内容,例如TypeEntity

+0

的确,我的数据库中有一个表格Type ...没有想到这一点。谢谢! – Matthias 2011-05-12 18:53:10

+0

我刚刚遇到了一个名为“EntityType”的表导致相同问题的问题。我只是将DataModel.Context.tt文件中的每个提及的“EntityType”都编辑为“System.Data.Metadata.Edm.EntityType”,而不是修复它。 – 2011-07-26 16:53:14

2

不要调用您的实体“类型”。在.NET中有一个真的很重要的类型,已经被称为Type。你只会用这个名字引起你的痛苦。选择一个与内置的基本类型名称不同的名称。

+0

是的,当然......没想过。谢谢。 – Matthias 2011-05-12 18:55:53