我正在尝试将我的网站首先由实体框架代码创建的数据库添加到azure中。一切似乎都不错,但我在种子I中的数据有两次。我试着写下我做过的步骤:
我认为这些是正确的步骤。但在我的本地数据库中,一切都很好,但在天蓝色的情况下,一切都是两次。那么我该如何解决呢?
使用种子进行配置:
internal sealed class Configuration : DbMigrationsConfiguration<ObedoveMenuContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(ObedoveMenuContext context)
{
var cities = new List<City>
{
new City() { Name = "ExampleCity" },
new City() { Name = "ExampleCity2" },
};
cities.ForEach(c => context.Cities.AddOrUpdate(c));
...
}
}
和我的背景:
public class ObedoveMenuContext : DbContext
{
public ObedoveMenuContext() : base("name=ObedoveMenuContext")
{
}
public DbSet<City> Cities { get; set; }
public DbSet<Restaurant> Restaurants { get; set; }
public DbSet<Meal> Meals { get; set; }
public DbSet<ActionOffer> ActionOffers { get; set; }
}