【发布时间】:2015-12-28 07:21:31
【问题描述】:
我正在使用 EF 代码优先迁移:
https://msdn.microsoft.com/en-us/data/jj591621.aspx
add-migration、update-database等都是从VS中的包管理控制台调用的。
我还使用 SlowCheetah 来管理我们拥有的各种环境,特别是管理每个开发人员都有自己的数据库副本这一事实,以便他们可以更新他们的模型更改,而不会将其他人锁定在数据库之外。因此,更改的配置值之一是目标数据库名称。
(由于我不会详细说明的原因,我们没有使用 connectionStrings .config 设置,而是在 appSettings 块中使用 DB 名称)
我的包含模型和迁移的项目是 TheCustomer.Database 项目。
如果我手动更改 TheCustomer.Database/app.config 中的 appSetting 值,并运行迁移,它会正确使用配置值 - 所以配置基本上可以工作。
但是,如果我设置了一个 SlowCheetah 转换来修改给定构建配置的值,选择该配置,重新构建代码然后运行迁移,那么它不会应用转换;它使用基数 app.config 中的值,而不是 app.SelectBuildConfig.config
SlowCheetah 通常工作正常 - 当我运行 sln 来获取网站时,它使用的是 VS Build Config 确定的正确 Db。
有什么想法吗?
编辑:
配置文件:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<appSettings>
<add key="DbName" value="This Default Value shouldn't work - you should be using a value for a specific build" />
<add key="DbPassword" value="SomePassword" />
</appSettings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /></startup></configuration>
还有变换
<?xml version="1.0" encoding="utf-8" ?>
<!-- For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134. -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="DbName" value="LocalDev_MDM" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
【问题讨论】:
-
在您向我们展示 XDT 之前无法真正帮助您。
-
如何运行迁移?
-
找到这个petercallaghan.com/2015/04/… 但这不是问题
-
发现这个:stackoverflow.com/questions/21517602/… 但这显然也不是问题
-
@SergRogovtsev 见第一段。
update-database从 Pack 中运行。经理。缺点。
标签: c# entity-framework slowcheetah