你可以这样做 设置连接字符串 在创建时的EF Db上下文中,将您的设置值传递给您的EF上下文。
例如:在您的上下文中添加构造函数,该构造函数使用基本DbContext构造函数来传递连接字符串:
public class MyDbContext : DbContext { public MyDbContext(string connString) : base(connString) { } }
然后使用您的上下文,如:
var connectionString = "" // Get the value of of your custom config file here. var ctx = new MyDbContext(connectionString);
如上所述,您需要读取连接字符串值 的 第一 强> 出你的 settings.config 文件。
settings.config