EF 5.0 & dynamic connection string?

一曲冷凌霜 提交于 2019-12-18 04:09:47

问题


One thing is driving me crazy right now.

My (Database-first) EF-Model needs a dynamic connection string (IP-Adress of Server might change once in a while).

So in older EF-Versions you could pass a connection-string via constructor, but that is not possible in 5.0 as is seems.

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.

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?


回答1:


As petro mentions, you could create a partial class with the constructor you want.

For instance:

public partial class MyContext : DbContext
{
    public MyContext(string connectionString) : base(connectionString) {}
}


来源:https://stackoverflow.com/questions/12364617/ef-5-0-dynamic-connection-string

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