0

How can I move from Model First approach to Code First approach of Entity Framework development? I need it to enable EF Migrations.

1 Answers1

0

Try opening your Model First design and right clicking in the white area. Select add code generation item. This works on EF 4.1 and later. Select under Code "ADO.Net DbContext Generator.

This will create the class files from your model as if you were working in code first. From just create your own context and (optional) initializer as if you were working in code first. It is probably a good idea to move your class files to a Class Library, so that if you regenerate from the model your changes are not lost.

JabberwockyDecompiler
  • 3,318
  • 2
  • 42
  • 54
  • No, that's not a code first model. It still requires the presence of the edmx file to define the relationships. – Erik Funkenbusch May 03 '13 at 15:04
  • What I meant, is to take the class files that are created by the edmx, and use them as Code First. The class files would not need to be created and you would still need to setup the context that says what class models to use. It is not a direct conversion, but it would save the time of redoing the model. – JabberwockyDecompiler May 03 '13 at 15:25