2012-02-14 48 views
3

动了实体框架4.3 '更新数据库' 时配置文件被分开

AutomaticMigrationsEnabled = true; 

web.config有以下设置EF 4.3:

<appSettings configSource="appSettings.config" /> 
<connectionStrings configSource="connectionStrings.config" /> 

在包管理器控制台执行

update-database -verbose 

并得到以下错误:

System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config' 

错误是可以理解的:它试图从不到哪connectionStrings.config文件存在项目根目录的工作目录打开connectionStrings.config文件。

如果将connectionStrings.config和appSettings.config内容移动到web.config中,所有内容都像魅力一样工作。

它可以解决某个问题吗?

+0

相关:http://stackoverflow.com/questions/9264019/ef-4-3-migrations-throwing-unable-to-open-configsource-file – 2012-02-14 21:58:46

+0

检查此:https://plus.google.com/115980691282662298835/posts/UYxAuBQYySA – 2012-02-15 10:53:37

回答

1

看起来像这个错误是fixed in 4.3.1

Enabled support for configsource in configuration files when using Code First Migrations.

1

当迁移运行时,看起来二进制文件和配置文件被复制到临时目录。引用为configSource的文件不会被复制。我试过在构建中将configSource文件标记为复制,但没有运气。

我回到了将连接字符串正确放入包含我的dbcontext和migrations的类库的app.config。我有一个单独的类库,所以我的主Web项目的web.config仍然可以使用configSource

+0

正如@sashaeve指出的那样,这个问题已经在4.3.1中修复了,所以我的回答已经过时了。 – 2012-03-08 15:19:55

0

在这里使用EF 6.1。

如果像我这样链接到另一个项目中的connectionStrings.config文件,而不是Entity Framework迁移项目(使用Add作为链接),则可能需要将文件移回此EF项目并链接到从其他项目移动的文件,而不是...