使用EF4迁移工具与模型,第一种方法 [英] Using EF4 migration tool with model-first approach

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

问题描述

EF迁移实用程序首先使用code时,看起来相当不错。

EF migration utility seems quite nice when using code first.

href="http://www.$c$ctunnel.com/blog/post/111/introduction-to-entity-framework-43-migrations--part-ii">this博客文章,我想在我的项目中,我们使用的模型首先设置它。当运行时启用-迁移命令时,我得到以下错误:

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:

创建DbModelBuilder或写EDMX从的DbContext使用数据库优先或模型首先不支持创建。 EDMX只能从一个code首先的DbContext创建,而无需使用现有DbCompiledModel获得

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.

有什么办法解决它,所以我们可以使用EF迁移而无需切换到code-第一?

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.

基本上你使用自定义T4为模型生成DbMigrationsConfiguration和的DbContext,你不需要运行Enable-迁移的。只需运行加入迁移和更新,数据库的软件包管理器控制台。

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 /实体架构迁移与 - model.html

我会更新博客条目,T4,使之更人性化版本。

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

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

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