这是我的DbContext:与asp.core中的我的dbcontext问题。不知道如何使用DbContextOptions对象
public class ShoppingDbContext : IdentityDbContext<User>
{
public ShoppingDbContext(DbContextOptions options) : base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
}
public DbSet<Product> Products { get; set; }
}
今天早些时候,我得到了我通过把在构造函数你在我的代码中看到解决的错误。将DbContextOptions作为参数的那个。但现在,当我想创造这个的DbContext我不知道要放什么东西在参数的一个实例:
public static async Task<List<Product>> GetAllProducts()
{
//what should go in here?
ShoppingDbContext db = new ShoppingDbContext(?????????????);
return await db.Products.ToListAsync();
}
,如果我创建一个重载构造函数0参数,它不会解决导致它只是给我的问题在我使用DbContextOptions参数创建构造函数之前,我有同样的错误。我得到的错误,如果我有一个在dbcontext 0参数的构造函数是这样的:
没有数据库提供程序已配置此DbContext。可以通过重写DbContext.OnConfiguring方法或使用应用程序服务提供者上的AddDbContext来配置提供程序。如果使用AddDbContext,则还要确保您的DbContext类型在其构造函数中接受DbContextOptions对象,并将其传递给DbContext的基础构造函数。