How can I move from Model First approach to Code First approach of Entity Framework development? I need it to enable EF Migrations.
Asked
Active
Viewed 274 times
0
-
As in how to use the Migration feature or how to implement the feature? – Nomad101 May 03 '13 at 10:39
-
I mean how to implement Midration feature if I started with model fiirst approach – Dmitry Andrienko May 03 '13 at 10:45
-
Ah I see well take a look at this http://stackoverflow.com/questions/7333834/tool-to-convert-entity-framework-edmx-to-code-first – Nomad101 May 03 '13 at 10:47
-
Thanks, I hope EF Power Tools will be suitable for my project. – Dmitry Andrienko May 03 '13 at 10:58
1 Answers
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