Entity Framework database seed doesn't seed

后端 未结 1 1212
我在风中等你
我在风中等你 2021-01-24 11:21

I\'m quite new to EF. I\'m trying to override a Seed method inside my custom initializer, using MVC 4.

The problem is when EF creates the database, i don\'

相关标签:
1条回答
  • 2021-01-24 11:44

    You are not saving your changes to the database. Note that the default implementation of Seed does nothing.

    Try adding a call to SaveChanges in your Seed.

    protected override void Seed(EFDbContext context)
    {
        context.Admins.Add(new Admins
        {                
            Username = "admin",
            Password = "admin123456",
        });
        base.Seed(context);
        context.SaveChanges();
    }
    
    0 讨论(0)
提交回复
热议问题