Using EF4 migration tool with model-first approach
Asked Answered
M

2

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?

Masked answered 16/4, 2012 at 18:52 Comment(1)
I guess no - it is what the exception says but it would be a nice suggestion to Data UserVoice.Verisimilitude
K
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.

Kaohsiung answered 12/8, 2012 at 5:37 Comment(3)
Interesting, I will return to work in three weeks and make sure to check this, thanks.Masked
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.Masked
I meet the same problem. But the Code Second plugin doesn't work with EF 6...... How can this be solved?Philbrook
M
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".

Marguerite answered 11/5, 2012 at 11:51 Comment(0)
K
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.

Kaohsiung answered 12/8, 2012 at 5:37 Comment(3)
Interesting, I will return to work in three weeks and make sure to check this, thanks.Masked
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.Masked
I meet the same problem. But the Code Second plugin doesn't work with EF 6...... How can this be solved?Philbrook

© 2022 - 2024 — McMap. All rights reserved.