Reputation: 125
I am using Visual Studio 2012. I created a Class project and added EF data model to this project. I created the data model from an existing SQL Server Database. I created a MVC 4 project, added entity connection string to web config, and added data project reference.
All is good to this point.
Now I want to add a MVC controller using Entity Framework. I select a one of the model classes. I select the data context class. Click Add.
VS pops an error up, the last part of the error message is class might be in a compiled assembly {which is true}.
'AA' is not part of the specified 'aanamespace.aaEntity' class and the entity class could not be modified to a DbSet property to it. For example the 'aaEntity' might be in a compiled assembly
Upvotes: 4
Views: 4506
Reputation: 1538
Although this is a very old question, but there maybe people like me still facing the same issue which none of the suggested solutions can help them.
The reason for this error message when creating a new controller/scaffolding is the version of your EntityFramework.
HOW TO FIX:
if your project is MVC4 then you should use entity version 5. if you use Entity version 6 you will face this issue.
remove your .edmx file and add your EntityFramework version 5. it will work as expected.
Upvotes: 0
Reputation: 20078
I was in the same situation and I created a class library and in it i have all my .edmx and when i have a reference to my mvc project i got the exact the same error message i have posted my question here (stackoverflow.com/questions/18552864/…)
How did I fix:
Close the Visual Studio and open it again...
Upvotes: 4
Reputation: 8112
The problem was caused by the VSCommands for Visual Studio 2012 (Early Access) extension. Once I uninstalled it the problem disappeared.
Upvotes: 1
Reputation: 125
I want to take the time to answer this question myself so that others with a similar problem can be helped in the future.
Here is what I did.
Created the .edmx file in my Models folder of my MVC project. Built the MVC project
Now I can add a controller for any of the tables in the .edmx file.
Note: I thought the best practice was to create a project within my solution that holds the .edmx file. I called this project myData.
I added a reference to this project in my MVC project and tried this scaffolding without luck.
I hope this helps others because the solution is so simple.
Gerry
Upvotes: 3
Reputation: 5761
Without seeing the exact error, I can only suggest a problem I experienced with the EF controller scaffolding and how I got around it. If you have extended your EF context class with a partial class, you will have to remove the latter from your project and recompile before generating the controller, otherwise EF scaffolding refuses to work.
Upvotes: 0