Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework MVC Controller

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

like image 782
Gerry Whitworth Avatar asked Jan 15 '23 00:01

Gerry Whitworth


2 Answers

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...

like image 102
Nick Kahn Avatar answered Jan 30 '23 23:01

Nick Kahn


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

like image 41
Gerry Whitworth Avatar answered Jan 30 '23 22:01

Gerry Whitworth