事务=>数据库上下文错误提示

  No database provider has been configured for this DbContext. A provider can be configured by overriding the 'DbContext.OnConfiguring' method or by using 'AddDbContext' on the application service provider. If 'AddDbContext' is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

在你的数据库上下文里面添加如下类:

  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (!optionsBuilder.IsConfigured)
        {
            optionsBuilder.UseSqlServer("你的数据库连接字符串;MultipleActiveResultSets=true");
        }
    }
posted @ 2023-03-10 16:02  泽哥的学习笔记  阅读(209)  评论(0)    收藏  举报