How to add a new table with EF core

asp.net-core database entity-framework-core

Question

I have an existing database already that was created when i added Identity to the project. Now i wanna add more tables to the database and can't figure out how.

I have created a model for it:

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; }
}

My context:

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);
    }
}

What's the next steps?

1
5
8/29/2018 10:40:26 AM

Accepted Answer

You need to add the Match table in your DynamicBettingUserContext class like below. Then You need to add migration using Add-Migration <YourMigrationName> in Package Manager Console and finally, You have to run Update-Database command in PMC.

public virtual DbSet<Match> Match { get; set; } 
5
8/29/2018 10:41:07 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow