EF 5.0&安培;动态连接字符串? [英] EF 5.0 & dynamic connection string?
问题描述
有一件事情是让我疯了现在。
One thing is driving me crazy right now.
我(数据库一)EF-模型需要一个动态连接字符串(服务器的IP-ADRESS可能会换一次在一段时间)。
My (Database-first) EF-Model needs a dynamic connection string (IP-Adress of Server might change once in a while).
因此,在旧的EF-版本,你可以通过通过构造一个连接字符串,但那是不可能的5.0原样似乎
So in older EF-Versions you could pass a connection-string via constructor, but that is not possible in 5.0 as is seems.
我读过到目前为止,你可以改变你的DataTemplate,但会在您每次都会覆盖重新生成模型等,所以不能做到这一点的最好办法。
What I have read so far, you could change your datatemplate, but that will be overwritten each time you re-generate your model etc., so not the best way to do it.
另一件事是SQLConnectionFactory,但似乎并没有在所有
(Database.DefaultConnectionFactory =新SqlConnectionFactory(工作.. 。)
似乎被完全忽略)。
Another thing is the SQLConnectionFactory, but that does not seem to work at all
(Database.DefaultConnectionFactory = new SqlConnectionFactory( ... )
seems to be ignored completely).
什么是对,正确的方法呢?
What would be the right approach for that?
推荐答案
随着石油中提到,您可以创建你想要的构造部分类
As petro mentions, you could create a partial class with the constructor you want.
例如:
public partial class MyContext : DbContext
{
public MyContext(string connectionString) : base(connectionString) {}
}
这篇关于EF 5.0&安培;动态连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!