10

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?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Johnny5
  • 6,664
  • 3
  • 45
  • 78
  • 1
    I guess no - it is what the exception says but it would be a nice suggestion to [Data UserVoice](http://data.uservoice.com/forums/72025-entity-framework-feature-suggestions). – Ladislav Mrnka Apr 16 '12 at 18:57

2 Answers2

3

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".

artisonus
  • 76
  • 4
3

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.

Peijen
  • 83
  • 2
  • 6
  • Interesting, I will return to work in three weeks and make sure to check this, thanks. – Johnny5 Aug 12 '12 at 13:25
  • I did not apply that to my project yet, not sure if it will works "out of the box", but it seems to be the only solution so far. – Johnny5 Oct 05 '12 at 15:50
  • I meet the same problem. But the Code Second plugin doesn't work with EF 6...... How can this be solved? – Franva Apr 06 '15 at 13:42