Sunday, June 12, 2016

Generating Entity Framework Code First POCO classes from an existing Entity Framework Model (EDMX file)

If you have an existing Entity Framework model (EDMX file) you generated from your database and you would like to generate POCO classes for using as Domain Classes or for Entity Framework Code First, you can easily accomplish this using Code Generation!

  1. Right click on your Entity Framework model and select "Add Code Generation Item"
  2. You will then be prompted to select a Visual Studio Template.  Based on the version of Entity Framework that you are using, you can choose either "EF 5.x DbContext Generator" or "EF 6.x DbContext Generator".  For my particular example, I am using Entity Framework 6, so I ended up using "EF 6.x DbContext Generator"
  3. Finally, once you choose your Entity Framework Code Generation template, you will then be prompted to run the template.  
  4. When prompted with the warning dialog about running templates on your computer, make sure you click "OK" in order to allow the template to run.  You may be prompted multiple times, so you may have to either click "OK" multiple times or select the checkbox for "Do not show this message again"
  5. Once you have completed running the code generation templates, you will have your generated code classes!

No comments:

Post a Comment