Entity Framework 4.3: 'update-database' when configuration files are separated

馋奶兔 提交于 2019-12-13 13:45:17

问题


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?


回答1:


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 the configSource 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.




回答2:


Seems like this error was fixed in 4.3.1.

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




回答3:


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...



来源:https://stackoverflow.com/questions/9284289/entity-framework-4-3-update-database-when-configuration-files-are-separated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!