小编Ash*_*ley的帖子

Database.EnsureCreated() 不创建表

我正在关注本教程: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)

.net entity-framework .net-core

5
推荐指数
1
解决办法
3884
查看次数

标签 统计

.net ×1

.net-core ×1

entity-framework ×1