Code First to Existing Database (EF6.1 Onwards)

Play Code First to Existing Database (EF6.1 Onwards)

The Discussion

  • User profile image

    A feature I haven't been able to confirm exists (and stack overflow the sole response I got was you can't do it) but would be a nice integration point:  sql extendedproperties: should be able to create and or get them back from the database to your code first model. At my work we have a fairly complicated database that we allow third party distributors to develop against. We need to be able to among other things document tables/columns in the db itself. Having a code first but then having to go into the database and manually add the documentation afterwards seems a bit like a cludge.

  • User profile image

    @madscientist:Document your code-first POCO's and use Sandcastle instead.

  • User profile image

    I have VS2013 Professional installed, and have created a new MVC project. First thing I do is use NuGet to update all packages in project, which includes upgrading EF from 6.0 to 6.1.
    However, when I go to add a new ADO.NET Entity Data Model (as shown at 0:43 in the video), the dialog I have only shows me two choices, and "Code First from Database" is not one of them. (As shown at 0:47 in the video.) I have looked around for any other updates and am not sure where I am supposed to find this option. The "Get Entity Framework" link tells me this is already installed with VS2013, so I'm not sure what I'm missing.

  • User profile image

    To follow up on my own comment, the "Get Entity Framework" link has incorrect information on it. { } It says that the tooling is already installed vith VS2013, but you need to click on the link to download for VS2012 --- and then there you will see there actually is something new you need to download for VS2013. In any case, this is all it took for me to get this working as shown in the video. Thank you!

  • User profile image

    @Fzznk:Did it create the model classes within the Models mvc folder?  And did it create controllers for you?  When I tried with an mvc 4 project it created the models but put them in the Controllers folder.  It didn't create controllers for me based on the models.  I expected it to do all that for me.

  • User profile image

    What about performance?

    Is it doing better than dapper.NET?

  • User profile image

    @Fzznk I have the same problem in VS2013 and fix it after update 2 installed. (no need to install EF Tools)

  • User profile image


    Can anyone guide me? i am facing an issue and still couldn't be able solve it.

    i shall be very thankful to you.

    please the problem at here

  • User profile image

    Thanks for this tutorial.

    Anyway I have a question and I hope you can help me with this. We have an existing database (we're not using EF) and we are required to use it on our new project.

    For this new project, I would like to use Entity Framework, and upon stumbling on your post I've learned how to use 'Code First From Database'. Problem is, since most of our previous project is not using EF, the database structure can be changed by our DBA (not using EF).

    So after the initial creation of my models/context using 'Code First From Database', our DBA decided to add new tables/columns. How can I sync those changes to my initially created models?


  • User profile image

    Nice, thank you. I was wondering if there were a way to just create the needed classes and everything from a single table within a Context that already exists, without having to generate a whole new context?

  • User profile image
    suresh babu

    I see only Tables and views, how to fetch store procedures

Add Your 2 Cents