我已经有一个现有的数据库,这是我在将 Identity 添加到项目时创建的。现在我想向数据库添加更多表,但不知道如何。
我为它创建了一个模型:
public class Match
{
public Guid ID { get; set; }
public string HomeTeam { get; set; }
public string AwayTeam { get; set; }
public int FullTimeScore { get; set; }
public DateTime MatchStart { get; set; }
public int PrizePool { get; set; }
}
我的背景:
public class DynamicBettingUserContext : IdentityDbContext<IdentityUser>
{
public DynamicBettingUserContext(DbContextOptions<DynamicBettingUserContext> options)
: base(options)
{
}
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
// Customize the ASP.NET Identity model and override the defaults if needed.
// For example, you can rename the ASP.NET Identity table names and more.
// Add your customizations after calling base.OnModelCreating(builder);
}
}
接下来的步骤是什么?
您需要在DynamicBettingUserContext
类中添加Match
表,如下所示。然后,您需要在程序包管理器控制台中使用Add-Migration <YourMigrationName>
添加迁移,最后,您必须在PMC中运行Update-Database
命令。
public virtual DbSet<Match> Match { get; set; }