If you are just starting out with the MvcScaffolding Nuget package to scaffold your basic CRUD operations on an MVC3 project, you should know that it requires EF 4.1 to run correctly without the following error.
The type 'LPM.Project' was not mapped. Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation. Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject
If you already ran the scaffolding via the Package Manager Console using syntax similar to the following, PM>scaffold controller <table> –Repository –Force, to resolve the error, I needed to:
- Delete the scaffolded controller files and view files from the project.
- Install the Entity Framework 4.1
- Re-Generate the Database From Model (assuming that is how you created the Entities to begin with)
- Right click on the .edmx Design surface, click Add Code Generation Item.
- Click the Code link in the Installed Templates tree. Select ADO.Net DbContext Generator. Name the code generation template, it ends with a .tt extension.
- Rebuild the project.
- Re-scaffold the tables.
- Run the project
Steps 4 & 5 above were the key to getting it to work after installing the Entity Framework 4.1 and with all my combinations of re-scaffolding, re-generating the model, re-creating the model, etc. That important bit of information came from MVC 3 Scaffolding issue with Entity Framework.
If you look at the Model.designer.cs (or .vb) code prior to adding the ADO.Net DbContext Generator, you will see that the Model entities do inherit from the EntityObject (which is noted in the error message as a potential cause of the exception). Adding the ADO.Net DbContext Generator disables the default code generation and inherits from the DbContext instead.
more information:
- Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package
- Entity Framework Scaffolding: The type is not mapped issue
- A word of Advice. Don't get EF 4.1 via NuGet
- EF 4.1 Code First Walkthrough – I already had a database so this wasn’t really applicable to my situation.
No comments:
Post a Comment