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)



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
  1. Walt Daniels
    March 13, 2013 at 1:28 am

    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

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

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

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

  4. September 11, 2013 at 8:38 am

    i had same situation the above trick did not fix mine and the way i able to fix it by restarting the visual studio that’s correct restarting the visual studio, hope this will help others.

  5. October 4, 2013 at 12:10 am

    Life saver … I was getting well puzzled why it wouldn’t generate

  6. mine
    October 14, 2013 at 10:16 pm

    Cant Thank You enough, this was frustrating the @#$%^%^ out of me.

  7. G. Chen
    October 24, 2013 at 5:05 am


  8. manish dalwadi
    April 16, 2014 at 7:46 pm


  9. Vishmay
    June 27, 2014 at 1:08 pm

    Object Reference not set to an Instance of Object Error

  10. Amman
    July 11, 2014 at 2:26 am

    Thanks God Bless You 🙂

  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 )

Google+ photo

You are commenting using your Google+ 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

%d bloggers like this: