IIS启动时调用EF种子

时间:2017-03-27 13:57:33

标签: ef-code-first

我们使用EF Code First种子方法来部署我们的项目参数。当我们在任何时候重新启动iis时,种子方法再次工作并更新数据。为什么再次打电话?

我们的配置文件:

  public Configuration()
    {
        AutomaticMigrationsEnabled = false;
    }

    protected override void Seed(FastVContext context)
    {

        #region Menu And Sub Menu

        context.MenuItems.AddOrUpdate(x => x.Id,
           new MenuItem()
           {
               Id = 1,
               MenuName = "Özet",
               Priority = 100,
               cssClass = "fa fa-tachometer",
               Controller = "Home",
               PageURL = "/"

           },
             new MenuItem()
             {
                 Id = 2,
                 MenuName = "Genel Ayarlar",
                 Priority = 60,
                 cssClass = "fa fa-cogs",
                 Controller = null

             },

}

我们的上下文文件

protected override void OnModelCreating(DbModelBuilder modelBuilder)         {

        base.OnModelCreating(modelBuilder);
        modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

。 。 }

1 个答案:

答案 0 :(得分:0)

完成本教程: https://docs.microsoft.com/en-us/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application

您可以使用属性disableDatabaseInitialization =&#34; false&#34;跳过初始化程序,这是数据种子和DropCreateDatabaseIfModelChanges发生的地方。

var levelCost = Math.floor(200 * Math.pow(1.12, level));