使用具有模型优先方法的EF4迁移工具 [英] Using EF4 migration tool with model-first approach

查看:266
本文介绍了使用具有模型优先方法的EF4迁移工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



根据本博客,我尝试在我的项目中设置它,我们使用model-first。当运行启用迁移命令时,我收到以下错误:


创建一个DbModelBuilder或从使用Database First或Model First创建的DbContext写入EDMX是不受支持的。 EDMX只能从不使用现有DbCompiledModel创建的Code First DbContext获取。


有没有办法让我们可以使用EF迁移而不需要转换为代码优先?

解决方案

我有一个不完整的博客条目,您可以如何做到这一点。不确定是否符合您的需要,但似乎是目前唯一可用的方法。



基本上,您使用自定义t4从您的模型生成DbMigrationsConfiguration和DbContext根本不需要运行Enable-Migration。只需在包管理器控制台中运行Add-Migration和Update-Database。



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



我将会更新博客条目和t4,以便稍后更加用户友好。


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?

解决方案

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.

这篇关于使用具有模型优先方法的EF4迁移工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆