【发布时间】:2017-11-12 00:12:01
【问题描述】:
我有一个我正在尝试使用的ConfigurationDbContext。它有多个参数,DbContextOptions 和 ConfigurationStoreOptions。
如何将此 DbContext 添加到我在 ASP.NET Core 中的服务中?
我在 Startup.cs 中尝试了以下操作:
ConfigureServices
....
services.AddDbContext<ConfigurationDbContext>(BuildDbContext(connString));
....
private ConfigurationDbContext BuildDbContext(string connString)
{
var builder = new DbContextOptionsBuilder<ConfigurationDbContext>();
builder.UseSqlServer(connString);
var options = builder.Options;
return new ConfigurationDbContext(options, new ConfigurationStoreOptions());
}
【问题讨论】:
-
你用的是mssql server吗
-
是的。但是,要构造 dbcontext,我需要向它传递另一个参数。
-
我还添加了示例链接
标签: c# entity-framework dependency-injection asp.net-core entity-framework-core