我想不通爲什麼我突然得到這些編譯錯誤。讓我們通過我採取的步驟:使用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文件夾中或硬盤驅動器上的外部位置也無關緊要。
有沒有人有任何想法,爲什麼這是失敗?謝謝。
的確,我的數據庫中有一個表格Type ...沒有想到這一點。謝謝! – Matthias 2011-05-12 18:53:10
我剛剛遇到了一個名爲「EntityType」的表導致相同問題的問題。我只是將DataModel.Context.tt文件中的每個提及的「EntityType」都編輯爲「System.Data.Metadata.Edm.EntityType」,而不是修復它。 – 2011-07-26 16:53:14