Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using EF4 migration tool with model-first approach

EF migration utility seems quite nice when using code first.

Based on this blog post, I tried setting it in my project where we use model-first. When running Enable-Migrations command, I get the following error:

Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.

Is there any way around it so we can use the EF migration without switching to code-first?

like image 308
Johnny5 Avatar asked Apr 16 '12 18:04

Johnny5


2 Answers

I have an incomplete blog entry on how you could do this. Not sure if it will fit your need, but seems to be the only method available so far.

Basically you use custom t4 to generate DbMigrationsConfiguration and DbContext from your model and you don't need to run Enable-Migration at all. Simply run Add-Migration and Update-Database in the Package Manager Console.

http://blog.amusedia.com/2012/08/entity-framework-migration-with-model.html

I will be update the blog entry and t4 to make it more user friendly later.

like image 199
Peijen Avatar answered Sep 22 '22 23:09

Peijen


I was looking for the same solution and found this: Entity Designer Database Generation Power Pack After installation, when you choose "Generate Database from Model..." it'll popup a new wizard and you can choose "Generate Migration T-SQL".

like image 35
artisonus Avatar answered Sep 22 '22 23:09

artisonus