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

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

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)

image

 

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

image

 

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)

image

 

Now clicking Add will do the neccessary

About these ads
Categories: ASP.NET, MVC
  1. Walt Daniels
    March 13, 2013 at 1:28 am | #1

    Thank you for this! After much googling, this worked! Who would’ve thought … manually type in the Data context class!!! C’mon Microsoft, fix this!

  2. James DIas
    May 4, 2013 at 12:56 am | #2

    this no exists, start vs2012 with admin user and problem no fired

  3. Sujoy
    June 3, 2013 at 7:11 pm | #3

    This is great, I have many nerds giving a lot of solutions for this problem but you are just great. Thanks.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: