【发布时间】:2020-12-18 03:51:00
【问题描述】:
我正在使用带有新实体框架核心的旧应用程序(标准 .net 框架 wpf 应用程序)。
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(@"server=baaa;database=baaa;User=saaa;Password=xsaa1;");
}
但我想将我的连接字符串移动到 App.config 或其他地方并从那里读取它,而不是保持硬编码。
由于我的 WPF 应用程序不是 .net 核心 WPF 应用程序,因此我不能使用 DI 编写如下内容:
IConfigurationRoot configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
那么问题是如何在实体框架核心的 DbContect 中从我的旧 WPF (.NET FRAMEWORK) 应用程序中读取连接字符串?
谢谢
干杯
【问题讨论】:
标签: c# wpf entity-framework .net-core