我有一个带有实体框架的.NET Core 6 Web应用程序.
我的DbContext类似于:
public class MyDbContext : DbContext
{
public MyDbContextDbContext(DbContextOptions<MyDbContext> options)
: base(options)
{
// How to set it from configuration options
this.HasCustomFeature = ...
}
...
}
如何在使用以下配置选项时忽略配置选项:
services.AddDbContext<Model.MyDbContext>(options =>
options.UseSqlServer(
Configuration.GetConnectionString("DefaultConnection")));
...这样我就可以在构造函数中读取它了通常HasCustomFeature
设置值来自DbContext外部的应用程序选项.