我正在关注本教程:https : //docs.microsoft.com/en-us/aspnet/core/data/ef-mvc/intro
TournamentDbContext.cs:
public class TournamentDbContext : DbContext
{
    public TournamentDbContext(DbContextOptions<TournamentDbContext> options) : base(options)
    {
    }
    public DbSet<Tournaments> Tournaments { get; set; }
    public DbSet<TournamentType> TournamentType { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
程序.cs
  public static void Main(string[] args)
    {
        var host = BuildWebHost(args);
        using (var scope = host.Services.CreateScope())
        {
            var services = scope.ServiceProvider;
            try
            {
                var TournamentDb = services.GetRequiredService<TournamentDbContext>();
                DbInitializer.Initialize(TournamentDb);
            }
            catch (Exception ex)
            {
                var logger = services.GetRequiredService<ILogger<Program>>();
                logger.LogError(ex, "An error occurred while seeding the database.");
            }
        } …Run Code Online (Sandbox Code Playgroud)