private void CustomMigration(string key, System.Data.Entity.Migrations.DbMigrator migrator,
                              Migrations.Configuration config, AtlanticDXContext context)
 {
     //migrator.Update(key);
     ////var config = new AtlanticDX.ERP.Migrations.Configuration();
     //if (this.GetForceExternalSeedingFromConfig())
     config.SeedExternal(context, key);
 }
        private void InitDatabases()
        {
            //debug
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
            var test = Devart.Data.MySql.Entity.MySqlEntityProviderServices.Instance;

            System.Data.Entity.DbConfiguration.Loaded +=
                (sender, e) =>
                e.ReplaceService <System.Data.Entity.Core.Common.DbProviderServices>(
                    (services, o) =>
                    Devart.Data.MySql.Entity.MySqlEntityProviderServices.Instance
                    );

            try
            {
                LogHelper.Info("Start Code First Upgrade Database to latest......");

                //必须留下下面这行,配置使用Devart数据生成MySQL的脚本
                System.Data.Entity.Database.SetInitializer(
                    //new System.Data.Entity.DropCreateDatabaseIfModelChanges<AtlanticDXContext>());
                    new DevartDbMigrationInitializer());

                var config = new Migrations.Configuration();

                using (AtlanticDXContext context = new AtlanticDXContext())
                {
                    System.Data.Entity.Migrations.DbMigrator migrator
                        = new System.Data.Entity.Migrations.DbMigrator(config);
                    config.TargetDatabase = new System.Data.Entity.Infrastructure.DbConnectionInfo(
                        context.Database.Connection.ConnectionString, "Devart.Data.MySql");
                    var migrationsss = migrator.GetDatabaseMigrations();
                    var temp11       = migrator.GetLocalMigrations();
                    var temp22       = migrator.GetPendingMigrations();

                    temp22 = temp22.Except(migrationsss);

                    if (temp22 != null && temp22.Count() > 0)
                    {
                        LogHelper.Info(string.Format("Start Code First force default migrations......"));
                        migrator.Update();
                        LogHelper.Info("Finish Code First default migration. ");
                    }
                    else if (this.GetForceExternalSeedingFromConfig())
                    {//20150120 liangdawen: force to seed!
                        LogHelper.Info(string.Format("Start Code First force Seeding external......"));
                        migrator.Update();
                        LogHelper.Info("Finish Code First force Seeding external. ");
                    }

                    //20150131 custom migration seeding
                    string[] upgrades = GetUpgradesFromConfig();
                    if (upgrades != null && upgrades.Length > 0)
                    {
                        LogHelper.Info(string.Format("Start Code First force custom seeds......"));
                        foreach (var key in upgrades)
                        {
                            this.CustomMigration(key, migrator, config, context);
                            LogHelper.Info(string.Format("Finish Code First custom seed: {0} .", key));
                        }
                        LogHelper.Info("Finish Code First force custom seeds. ");
                    }

                    LogHelper.Info(string.Format("Code First Upgrade Database to latest completed."));
                }
            }
            catch (Exception e)
            {
                string errMsg = "Start Code First Upgrade Database to latest Exception: "
                                + e.Message + "\t\t" + e.StackTrace;
                if (e.InnerException != null)
                {
                    errMsg += "\r\nInnerException: " + e.InnerException.Message + "\t\t"
                              + e.InnerException.StackTrace;
                }

                LogHelper.Error(errMsg);
            }
        }