Search code examples
c#asp.netentity-frameworkvisual-studio-2013

Regenerate Entity Framework Code First Models


Using Entity Framework 6 Code First in an ASP.NET project with Visual Studio 2013, is there any way to rebuild (or update) the generated DataContext and model classes without stepping through the Entity Data Model Wizard every time?

I'm fully aware of how to do this with an EDMX designer, but again, I'm using the "Code First from database" method and just wondering if there's a one-click (or one console command) way to trigger the rebuild without having to delete the generated context class and then step through the Entity Data Model Wizard every time I make a change to the backing database.


Solution

  • In VS 2015 (and supposedly 2013/2012) you can use the Entity Framework Reverse POCO generator to accomplish this.

    https://visualstudiogallery.msdn.microsoft.com/ee4fcff9-0c4c-4179-afd9-7a2fb90f5838

    You can make all your changes to database first, and to re-generate your models all you have to do is save your Database.tt file (usually I just add white space).