Archive for February, 2013

ASP.NET MVC4– How to use a Database First EF in a MVC controller

February 19, 2013 11 comments

Typically when you generate an Entity Framework (.edmx) from database and then try to create a MVC controller with read/write actions based on this Entity Framework, you will get the following error


xxx is not part of the specified Entity class, and the Entity Class could not be modified to add a DbSet<xxx> property to it. (For example, the Entity class might be in a compiled assembly)



Typically when you follow the steps, you will end up with the screen below, which will give you the error above when you click Add



For some strange reason, this DOESN’T work well with Database first EF, but it works properly with Code First EF.

To get it to work, all you need to do is to

1. Compile the project

2. Manually type in the Data context class (or remove the text in brackets)



Now clicking Add will do the neccessary

Categories: ASP.NET, MVC