我已经定义了以下应用程序上下文类。
public class ApplicationContext : DbContext
{
public DbSet<User> Users{ get; set; }
public ApplicationContext(DbContextOptions<ApplicationContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.ApplyConfiguration(new UserConfiguration());
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddDbContext<ApplicationContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("PostgreSQLConnection")));
}
UserConfiguration.cs
internal class UserConfiguration : IEntityTypeConfiguration<User>
{
public void Configure(EntityTypeBuilder<User> builder)
{
builder.ToTable("Users");
builder.HasKey(c => c.Id);
builder.Property(x => x.Id).HasDefaultValueSql("newsequentialid()");
}
}
当我应用命令Add-migration somemigration时,它将创建带有文件的整个迁移历史记录,并且在Update-Database
之后,它将创建数据库和表Accounts。但是,当我键入Update-Database -Verbose
时,它将仅创建没有表的数据库。我应该添加些什么来启用此功能?