• Entity Framework数据库初始化四种策略


    策略一:数据库不存在时重新创建数据库

    Database.SetInitializer<testContext>(new CreateDatabaseIfNotExists<testContext>());


    策略二:每次启动应用程序时创建数据库

    Database.SetInitializer<testContext>(new DropCreateDatabaseAlways<testContext>());


    策略三:模型更改时重新创建数据库

    Database.SetInitializer<testContext>(new DropCreateDatabaseIfModelChanges<testContext>());


    策略四:从不创建数据库

    Database.SetInitializer<testContext>(null);


    Entity Framework数据库初始化示例

    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using Web.Models.Mapping;

    namespace Web.Models
    {
        public class testContext : DbContext
        {
            static testContext()
            {
                Database.SetInitializer<testContext>(null);
            }

            public testContext()
                : base("Name=testContext")
            {
            }

            public DbSet<Person> People { get; set; }

            protected override void OnModelCreating(DbModelBuilder modelBuilder)
            {
                modelBuilder.Configurations.Add(new PersonMap());
            }
        }
    }
  • 相关阅读:
    前端埋点2怎么埋点
    .net core
    Qto_DoorBaseQuantities
    Qto_WallBaseQuantities
    Qto_SlabBaseQuantities
    Qto_RampFlightBaseQuantities
    Pset_WallCommon
    Pset_StairCommon
    matlab 矩阵变换
    Qto_CoveringBaseQuantities
  • 原文地址:https://www.cnblogs.com/nele/p/6993606.html
Copyright © 2020-2023  润新知