相关疑难解决方法(0)

可以通过覆盖DbContext.OnConfiguring来配置提供程序

出于某种原因,因为我添加了一个Application User类,它说我有两个上下文,但我没有,但我按照以下方式创建了类:

public class ApplicationDbContextFactory : IDbContextFactory<solitudeDContext>
    {
        public solitudeDContext Create(DbContextFactoryOptions options)
        {
            var optionsBuilder = new DbContextOptionsBuilder<solitudeDContext>();
            return new solitudeDContext(optionsBuilder.Options);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

但现在它说的如下:

没有为此DbContext配置数据库提供程序.可以通过覆盖DbContext.OnConfiguring方法或在应用程序服务提供程序上使用AddDbContext来配置提供程序.如果使用AddDbContext,那么还要确保您的DbContext类型在其构造函数中接受DbContextOptions对象,并将其传递给DbContext的基础构造函数.

这是我的数据库上下文层:

public class solitudeDContext : IdentityDbContext<IdentityUser>
    {  public solitudeDContext(DbContextOptions<solitudeDContext> options) : base(options)
        {
        }
        public DbSet<basketheader> BasketHeader { get; set; }
        public DbSet<basketlines> BasketLines { get; set; }
        public DbSet<customer> Customer { get; set; }

        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            builder.Entity<ApplicationUser>(entity =>
            {
                entity.ToTable(name: "AspNetUser", schema: "Security");
                entity.Property(e => e.Id).HasColumnName("AspNetUserId");

            });

        } …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-core

7
推荐指数
1
解决办法
6864
查看次数

标签 统计

asp.net ×1

asp.net-core ×1

c# ×1