【发布时间】:2021-08-10 02:46:57
【问题描述】:
您不能在 EF7 上将相对连接字符串与 SQLite 一起使用,因此我需要一种在配置 DBContext 的 ConfigureServices 例程期间从 Startup.cs 中获取应用程序目录的方法。
知道如何使用 .NetCoreApp 库执行此操作吗?
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
//Figure out app directory here and replace token in connection string with app directory.......
var connectionString = Configuration["SqliteConnectionString"];
if (string.IsNullOrEmpty(connectionString))
throw new Exception("appSettings.json is missing the SqliteConnectionString entry.");
services.AddDbContext<MyContext>(options =>
{
options.UseSqlite(connectionString, b => b.MigrationsAssembly("xyz.myproject.webapp"));
});
}
【问题讨论】:
标签: c# asp.net-core