internal ManagedConnectionDbAccesser(DbSetting dbSetting)
        {
            if (dbSetting == null) throw new ArgumentNullException("dbSetting");

            _connectionManager = TransactionDependentConnectionManager.GetManager(dbSetting);

            _dba = new DbAccesser(dbSetting, _connectionManager.Connection);
        }
示例#2
0
        protected override void RunCore(IDbAccesser db)
        {
            //db.Connection.Close();

            //连接到 MASTER 数据库
            var master = new SqlConnectionStringBuilder(db.Connection.ConnectionString) { InitialCatalog = "MASTER" };

            //参考 EntityFramework SqlProviderServices.DbDeleteDatabase()
            SqlConnection.ClearPool(db.Connection as SqlConnection);

            using (var db2 = new DbAccesser(master.ConnectionString, DbSetting.Provider_SqlClient))
            {
                db2.ExecuteText(string.Format("DROP DATABASE [{0}]", this.Database));
            }
        }
示例#3
0
        public void DMT_ManualMigrate()
        {
            using (var context = new RafyDbMigrationContext(UnitTestEntityRepositoryDataProvider.DbSettingName))
            {
                context.HistoryRepository = new DbHistoryRepository();
                context.RunDataLossOperation = DataLossOperation.All;

                try
                {
                    context.ManualMigrations.Clear();
                    context.ManualMigrations.Add(new DMT_ManualMigrateEntity());
                    context.ManualMigrations.Add(new DMT_ManualMigrateTest());

                    //手工更新
                    context.MigrateManually();

                    //历史记录
                    var histories = context.GetHistories();
                    Assert.IsTrue(histories.Count == 2);
                    Assert.IsTrue(histories[0] is DMT_ManualMigrateTest);
                    Assert.IsTrue(histories[1] is DMT_ManualMigrateEntity);

                    //数据库结构
                    var database = context.DatabaseMetaReader.Read();
                    var table = database.FindTable("TestingTable");
                    Assert.IsTrue(table.Columns.Count == 2);
                    var pk = table.FindPrimaryColumn();
                    Assert.IsTrue(pk.Name.EqualsIgnoreCase("Id"));
                    Assert.IsTrue(pk.DataType == DbType.Int32);

                    //数据库数据
                    using (var db = new DbAccesser(UnitTestEntityRepositoryDataProvider.DbSettingName))
                    {
                        var rows = db.QueryDataTable("select * from TestingTable");
                        Assert.IsTrue(rows.Rows.Count == 2);
                    }
                    var repo = RF.Find<TestUser>();
                    Assert.IsTrue(repo.CountAll() == 10);
                }
                finally
                {
                    //回滚
                    context.RollbackAll(RollbackAction.DeleteHistory);

                    var database = context.DatabaseMetaReader.Read();
                    Assert.IsTrue(database.FindTable("TestingTable") == null);
                }
            }
        }