我正在使用 AspCore 2 实现代码优先数据库。我有一个“DataContext.cs”,如下所示:
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string MiddelName { get; set; }
public string LastName { get; set; }
public bool IsActive { get; set; }
public DateTime? DateAdded { get; set; }
}
public class DataContext : IdentityDbContext<ApplicationUser>
{
public DataContext(DbContextOptions<DataContext> options) : base(options) {}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//AspNetUsers -> User
modelBuilder.Entity<ApplicationUser>()
.ToTable("User");
//AspNetRoles -> Role
modelBuilder.Entity<IdentityRole>()
.ToTable("Role");
//AspNetUserRoles -> UserRole
modelBuilder.Entity<IdentityUserRole>()
.ToTable("UserRole");
//AspNetUserClaims -> UserClaim
modelBuilder.Entity<IdentityUserClaim>()
.ToTable("UserClaim");
//AspNetUserLogins -> UserLogin
modelBuilder.Entity<IdentityUserLogin>()
.ToTable("UserLogin");
}
}
这在我的“startup.cs”中
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(x => x.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
当我尝试运行 dotnet 迁移时,dotnet ef migrations add InitialCreate出现以下错误:
“找到了多个 DbContext。指定要使用的 DbContext。对 PowerShell 命令使用“-Context”参数,对 dotnet 命令使用“--context”参数。”
你能帮我做对吗?谢谢!
叮当猫咪
隔江千里
一只萌萌小番薯
相关分类