/// <summary>
        /// 设置数据库初始化,策略为自动迁移到最新版本
        /// </summary>
        public static void Initialize()
        {
            CodeFirstDbContext context = new CodeFirstDbContext();
            IDatabaseInitializer <CodeFirstDbContext> initializer;

            if (!context.Database.Exists())
            {
                initializer = new CreateDatabaseIfNotExistsWithSeed();
            }
            else
            {
                initializer = new NullDatabaseInitializer <CodeFirstDbContext>();

                // initializer = new MigrateDatabaseToLatestVersion<CodeFirstDbContext, MigrationsConfiguration>();
            }

            Database.SetInitializer(initializer);

            //EF预热,解决EF6第一次加载慢的问题
            ObjectContext objectContext = ((IObjectContextAdapter)context).ObjectContext;
            StorageMappingItemCollection mappingItemCollection = (StorageMappingItemCollection)objectContext.ObjectStateManager
                                                                 .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);

            mappingItemCollection.GenerateViews(new List <EdmSchemaError>());
            context.Dispose();
        }
示例#2
0
        /// <summary>
        /// 设置数据库初始化,策略为自动迁移到最新版本
        /// </summary>
        public static void Initialize()
        {
            CodeFirstDbContext context = new CodeFirstDbContext();
            IDatabaseInitializer <CodeFirstDbContext> initializer;

            if (!context.Database.Exists())
            {
                initializer = new CreateDatabaseIfNotExistsWithSeed();
            }
            else
            {
                initializer = new MigrateDatabaseToLatestVersion <CodeFirstDbContext, MigrationsConfiguration>();
            }
            Database.SetInitializer(initializer);
        }
示例#3
0
        //public static readonly ICollection<Assembly> MapperAssemblies = new List<Assembly>();
        /// <summary>
        ///     设置数据库初始化,策略为自动迁移到最新版本
        /// </summary>
        public static void Initialize()
        {
            var context = new ChiakiYuDbContext();
            IDatabaseInitializer<ChiakiYuDbContext> initializer;
            if (!context.Database.Exists())
            {
                initializer = new CreateDatabaseIfNotExistsWithSeed();
            }
            else
            {
                initializer = new MigrateDatabaseToLatestVersion<ChiakiYuDbContext, Configuration>();
            }
            Database.SetInitializer(initializer);

            //EF预热,解决EF6第一次加载慢的问题
            var objectContext = ((IObjectContextAdapter) context).ObjectContext;
            var mappingItemCollection = (StorageMappingItemCollection) objectContext.ObjectStateManager
                .MetadataWorkspace.GetItemCollection(DataSpace.CSSpace);
            mappingItemCollection.GenerateViews(new List<EdmSchemaError>());
            context.Dispose();
        }