实体框架 4.3:“更新数据库”当配置文件分开时
已移至 ef 4.3,
AutomaticMigrationsEnabled = true;
在 web.config
中具有以下设置:
<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 中,一切都会像魅力一样。
这是一个错误吗?可以通过某种方式解决吗?
Moved to ef 4.3 with
AutomaticMigrationsEnabled = true;
In web.config
have the following settings:
<appSettings configSource="appSettings.config" />
<connectionStrings configSource="connectionStrings.config" />
In Package Manager Console execute
update-database -verbose
and got the following error:
System.Configuration.ConfigurationErrorsException: Unable to open configSource file 'connectionStrings.config'
The error is understandable: it tries to open connectionStrings.config
file from the working directory which is not the root project directory where connectionStrings.config
file exists.
If connectionStrings.config and appSettings.config content to be moved to the web.config all works like a charm.
Is it a bug a it can be solved somehow?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
运行迁移时,二进制文件和配置文件似乎被复制到临时目录。引用为
configSource
的文件不会被复制。我尝试标记要在构建中复制的 configSource 文件,但没有成功。我恢复将连接字符串直接放入包含 dbcontext 和迁移的类库的 app.config 中。我有一个单独的类库,因此主 Web 项目的 web.config 仍然可以使用 configSource。
When the migrations are run, it appears that binaries and the config file are copied to a temp directory. The files referenced as
configSource
are not copied over. I've tried marking theconfigSource
files to be copied in the build, to no luck.I reverted back to putting the connection string right into the app.config of the class library that contains my dbcontext and migrations. I have a separate class library for that, so my web.config of the main web project can still use
configSource
.似乎这个错误是 已在 4.3.1 中修复。
Seems like this error was fixed in 4.3.1.
此处使用 EF 6.1。
如果像我一样,您链接到位于实体框架迁移项目之外的另一个项目中的 connectionStrings.config 文件(使用添加为链接),您可能需要将文件移回此 EF 项目,并链接到移动的文件其他项目代替...
Using EF 6.1 here.
If like me you were linking to a connectionStrings.config file located in another project than your Entity Framework migrations project (using Add as link), you'll probably need to move the file back to this EF project and link to the moved file from the other projects instead...