MVC for Entity Framework

I am using Visual Studio 2012. I created a class project and added an EF data model to this project. I created a data model from an existing SQL Server database. I created an MVC 4 project, added an entity connection string to the web configuration, and added a link to the data project.

Everything is good at this point.

Now I want to add an MVC controller using the Entity Framework. I choose one of the model classes. I choose a data context class. Click Add.

VS gives an error message, the last part of the error message is a class that can be compiled in assembly {true).

"AA" is not part of the specified class "aanamespace.aaEntity", and the entity class cannot be changed to its DbSet property. For example, "aaEntity" may be in a compiled assembly

+4
source share
6 answers

I want to take the time to answer this question myself so that others with a similar problem can help in the future.

Here is what I did.

Created a .edmx file in my Mods folder of my MVC project. Built MVC project

Now I can add a controller for any of the tables in the .edmx file.

Note: I thought it was best practice to create a project in my solution containing the .edmx file. I called this project myData.

I added a link to this project in my MVC project and checked this project without any problems.


I hope this helps others because the solution is so simple.

Gerry

+3
source

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 link to my mvc project, I got the same error message that I posted here my question ( stackoverflow.com/questions/18552864 / ...)

How I fixed:

Close Visual Studio and open it again ...

+4
source

The problem is caused by the VSCommands extension for Visual Studio 2012 (Early Access). As soon as I deleted it, the problem disappeared.

+1
source

Run Visual Studio (Run as administrator) for me.

+1
source

Without seeing the exact error, I can only suggest the problem that I encountered with the EF controller winches, and how I got around it. If you extended your EF context class with a partial class, you will have to remove the last one from your project and recompile it before creating the controller, otherwise the EF scaffolding will refuse to work.

0
source

Although this is a very old question, but perhaps people like me still face the same problem that none of the proposed solutions can help them.

The reason for this error message when creating a new controller / forest is the version of your EntityFramework.

HOW TO SEARCH:

if your project is MVC4, then you must use the entity version 5. if you are using Entity version 6, you will run into this problem.

delete your .edmx file and add the EntityFramework version 5 version. It will work as expected.

0
source

Source: https://habr.com/ru/post/1446731/


All Articles