I can’t figure out why I suddenly get these compile errors. Let’s go through the steps I take:
1) I create a new MVC3 ASP.NET project (C#) using the Razor View engine
2) In my Models folder, I add an ADO.NET Entity Data Model, connect it to my database, and name it Database.edmx
3) I open my Database.edmx and select Add code generation item. I then add a Selft-Tracking Entity Generator and call it Model.tt
Everything is automaticly generated. When I hit build however, I get following compile errors:
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?)
To me, this makes no sense at all. I’ve created new projects with a database this way a dozen times and now, all of a sudden, I get these compile errors. It doesn’t make a difference what I name the database, edmx or models. It also makes no difference wether the database sits in the App_Data folder, or on an external location on my hard drive.
Does anyone have any idea why this is failing? Thanks.
It looks like there is a table
TYPESin your database that results in an entity classType. This class hides the classSystem.Type. Change the name of your entity to something else, e.g.TypeEntity.