实体框架代码首次数据迁移不能与VS2012 Web Deploy一起使用 [英] Entity Framework Code First Data Migrations not working with VS2012 Web Deploy

查看:173
本文介绍了实体框架代码首次数据迁移不能与VS2012 Web Deploy一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Visual Studio 2012,.NET 4.5和实体框架5.0创建了一个MVC 3.0应用程序。



使用代码优先数据迁移,我能够正确地传播模型更改到我的本地测试数据库,但我无法弄清楚如何使用Web Deploy部署到我的分段和生产服务器上工作。



我有阅读以下文章...



http://msdn.microsoft.com/en-us/library/dd394698(v = vs.110)#dbdacfx



...这解释了应该发生什么,但它对我来说并不起作用,因为Web Deploy似乎无法检测到我正在使用Entity Framework。本教程将显示一个复选框以启用代码优先迁移...





...但我的对话框显示了唯一的更新数据库复选框对于每个数据库,



我已经看到,为了Visual Studio检测到使用实体框架上下文, Web.config 必须包含一个定义它的元素。这是我的:

 < entityFramework> 
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>

< contexts>
< context type =MyContext,MyAssembly>
< databaseInitializer type =System.Data.Entity.MigrateDatabaseToLatestVersion`2 [[MyContext,MyAssembly],[MyConfig,MyAssembly]],EntityFramework>
< parameters>
< parameter value =MyConnectionStringName/>
< / parameters>
< / databaseInitializer>
< / context>
< / contexts>
< / entityFramework>

任何建议将不胜感激。





Tim

解决方案

这个问题通过实验。



事实上,我的MVC应用程序是由VS2012通过从VS2010解决方案转换而创建的。由于转换过程没有报告任何问题,我认为它正确地转换了所有内容,包括发布配置文件。



但是,我发现问题出在转换的这些配置文件,除非我手动编辑其XML文件,否则显然无法让旧的导入配置文件参与代码优先迁移。



只需创建新的发布配置文件在转换的解决方案中会导致预期的行为。


I have created an MVC 3.0 application using Visual Studio 2012, .NET 4.5 and Entity Framework 5.0.

Using Code First Data Migrations, I am able to correctly propagate model changes to my local test database, but I can't figure out how to get this to work when deploying to my staging and production servers using Web Deploy.

I have read the following article ...

http://msdn.microsoft.com/en-us/library/dd394698(v=vs.110)#dbdacfx

... which explains what's supposed to happen, but it's not working for me, as Web Deploy seems unable to detect that I am using Entity Framework. The tutorial shows a checkbox to enable execution of Code First Migrations ...

... but my dialog shows the only Update Database checkbox for each database.

I have read that, in order for Visual Studio to detect the use of an Entity Framework context, the Web.config must include an element that defines it. Here's mine:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

    <contexts>
        <context type="MyContext, MyAssembly">
            <databaseInitializer type="System.Data.Entity.MigrateDatabaseToLatestVersion`2[[MyContext, MyAssembly], [MyConfig, MyAssembly]], EntityFramework">
                <parameters>
                    <parameter value="MyConnectionStringName"/>
                </parameters>
            </databaseInitializer>
        </context>
    </contexts>
</entityFramework>

Any suggestions would be greatly appreciated.

Thanks,

Tim

解决方案

I have discovered the solution to this problem through experimentation.

In fact, my MVC application was created by VS2012 by converting from a VS2010 solution. Since the conversion process did not report any issues, I assumed that it had correctly converted everything, including the publishing profiles.

However, I discovered that the problem was in the conversion of these profiles and, unless I manually edit their XML files, there is apparently no way to get old imported profiles to participate in Code First Migrations.

Simply creating new publishing profiles in the converted solution results in the expected behavior.

这篇关于实体框架代码首次数据迁移不能与VS2012 Web Deploy一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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