EF 4.3迁移抛出“无法打开configSource文件”。 [英] EF 4.3 migrations throwing "Unable to open configSource file"

查看:92
本文介绍了EF 4.3迁移抛出“无法打开configSource文件”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用EF 4.3迁移功能。我的ASP.NET MVC项目将连接字符串存储在外部文件中:

I'm trying to use EF 4.3 migrations feature. My ASP.NET MVC project stores connection strings in external file:

<connectionStrings configSource="bin\connections.config" />

所有运行时过程(包括自动迁移)都可以正常工作。但是,连接到数据库的Powershell Commandlet无法找到外部文件。它将引发无法打开configSource文件异常。我试图将.config文件放在不同的位置,以及将配置的外部文件位置更改为无济于事。有任何解决方法吗?

All runtime procedures (including automatic migrations) work fine. However, no powershell commandlet, connecting to the database, is able to find external file. It throws "Unable to open configSource file" exception. I was trying to place .config file in different places as well as changing configured external file location to no avail. Is there any workaround available?

更新:我发现EF使用位于temp目录中的配置文件创建了一个临时AppDomain。因此,目前看来,唯一的解决方法是将外部配置放在相同的temp目录中。还有其他建议吗?

Update: I've found that EF creates a temporary AppDomain with configuration file located in temp directory. So the only workaround at the moment, it seems, is to place external configuration in the same temp directory. Any other suggestions?

推荐答案

很遗憾,没有简单的方法来处理外部 configSource 文件。我已经放弃了,将连接字符串移到了包含db代码的类库的配置文件中。另一种方法是,您发现自己可以手动复制文件。不幸的是,复制过程不符合项目的构建设置,因此设置要在构建时复制的外部配置文件无济于事。

There are unfortunately no easy way to handle external configSource files with the powershell cmd-lets in EF migrations. I've given up on it and moved the connection strings into the config file for the class library that contains the db code. The alternative is, as you've found out yourself to manually copy the file. Unfortunately the copy process doesn't honor the build settings of the project, so setting the external config file to be copied at build doesn't help.

EF 4.3.1 支持 configSource

这篇关于EF 4.3迁移抛出“无法打开configSource文件”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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