Esempio n. 1
0
 public static bool Equals(Column a, Column b)
 {
     if (a.Table.Name.EqualsIgnoreCase(b.Table.Name) &&
         a.Name.EqualsIgnoreCase(b.Name) &&
         DbTypeHelper.IsCompatible(a.DataType, b.DataType) &&
         //a.DataType == b.DataType &&
         a.IsRequired == b.IsRequired &&
         a.IsForeignKey == b.IsForeignKey &&
         a.IsPrimaryKey == b.IsPrimaryKey
         )
     {
         //判断外键是否相等
         //暂时不考虑NeedDeleteCascade是否相同的问题
         if (a.IsForeignKey &&
             !a.ForeignConstraint.PKColumn.Table.Name.EqualsIgnoreCase(b.ForeignConstraint.PKColumn.Table.Name))
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     else
     {
         return(false);
     }
 }
Esempio n. 2
0
        public void DMT_AlterColumn_DataType_AutoMigrate()
        {
            this.Test(destination =>
            {
            }, result =>
            {
                var table  = result.FindTable("Task");
                var column = table.FindColumn("XmlContent");
                Assert.IsTrue(column != null);

                var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName;
                Assert.IsTrue(DbTypeHelper.IsCompatible(column.DataType, DbType.Xml));
            });
        }
Esempio n. 3
0
 public void DMT_CreateColumn_Decimal()
 {
     this.Test(destination =>
     {
         var taskTable = destination.FindTable("Task");
         taskTable.AddColumn("TestingColumn", DbType.Decimal, isRequired: true);
     }, result =>
     {
         var taskTable = result.FindTable("Task");
         var c1        = taskTable.FindColumn("TestingColumn");
         Assert.IsTrue(c1 != null && c1.IsRequired);
         Assert.IsTrue(DbTypeHelper.IsCompatible(c1.DataType, DbType.Decimal));
     });
 }
Esempio n. 4
0
 public void DMT_AlterColumn_DataType_NullStringToDouble()
 {
     this.Test(destination =>
     {
         var taskTable = destination.FindTable("Task");
         taskTable.Columns.Remove(taskTable.FindColumn("Name"));
         taskTable.AddColumn("Name", DbType.Double, isRequired: true);
     }, result =>
     {
         var table  = result.FindTable("Task");
         var column = table.FindColumn("Name");
         Assert.IsTrue(column != null);
         Assert.IsTrue(DbTypeHelper.IsCompatible(column.DataType, DbType.Double));
         Assert.IsTrue(column.IsRequired);
     });
 }
Esempio n. 5
0
        private static ColumnChanges Distinguish(Column oldColumn, Column newColumn)
        {
            //if (newColumn == null) throw new ArgumentNullException("newColumn");
            //if (newColumn.Name.EqualsIgnoreCase(oldColumn.Name)) throw new InvalidOperationException("newColumn.Name.EqualsIgnoreCase(oldColumn.Name) must be false.");
            //if (newColumn.Table.Name.EqualsIgnoreCase(oldColumn.Table.Name)) throw new InvalidOperationException("newColumn.Table.Name.EqualsIgnoreCase(oldColumn.Table.Name) must be false.");

            ColumnChanges columnChanged = null;

            if (!Equals(newColumn, oldColumn))
            {
                columnChanged = new ColumnChanges(oldColumn, newColumn, ChangeType.Modified);

                if (newColumn.IsRequired != oldColumn.IsRequired)
                {
                    columnChanged.IsRequiredChanged = true;
                }

                if (newColumn.IsPrimaryKey != oldColumn.IsPrimaryKey)
                {
                    columnChanged.IsPrimaryKeyChanged = true;
                }

                if (!DbTypeHelper.IsCompatible(newColumn.DataType, oldColumn.DataType))
                {
                    columnChanged.IsDbTypeChanged = true;
                }

                //ForeignRelationChangeType
                columnChanged.ForeignRelationChangeType = ChangeType.UnChanged;
                if (!newColumn.IsForeignKey && oldColumn.IsForeignKey)
                {
                    columnChanged.ForeignRelationChangeType = ChangeType.Removed;
                }
                else if (newColumn.IsForeignKey && !oldColumn.IsForeignKey)
                {
                    columnChanged.ForeignRelationChangeType = ChangeType.Added;
                }
                else if (newColumn.IsForeignKey && oldColumn.IsForeignKey)
                {
                    if (!Equals(newColumn.ForeignConstraint, oldColumn.ForeignConstraint))
                    {
                        columnChanged.ForeignRelationChangeType = ChangeType.Modified;
                    }
                }
            }
            return(columnChanged);
        }
Esempio n. 6
0
        public void DMT_AlterColumn_DataType()
        {
            this.Test(destination =>
            {
                var taskTable = destination.FindTable("Task");
                taskTable.Columns.Remove(taskTable.FindColumn("Name"));
                taskTable.AddColumn("Name", DbType.Xml);
            }, result =>
            {
                var table  = result.FindTable("Task");
                var column = table.FindColumn("Name");
                Assert.IsTrue(column != null);

                var p = DbSetting.FindOrCreate(UnitTestEntityRepositoryDataProvider.DbSettingName).ProviderName;
                Assert.IsTrue(DbTypeHelper.IsCompatible(column.DataType, DbType.Xml));
            });
        }
Esempio n. 7
0
 public void DMT_CreateColumn_CLOB()
 {
     if (DbSetting.IsOracleProvider(UnitTest2EntityRepositoryDataProvider.DbSettingName))
     {
         this.Test(destination =>
         {
             var taskTable = destination.FindTable("Task");
             taskTable.AddColumn("TestingColumn", DbType.String, "CLOB", isRequired: true);
         }, result =>
         {
             var taskTable = result.FindTable("Task");
             var c1        = taskTable.FindColumn("TestingColumn");
             Assert.IsTrue(c1 != null && c1.IsRequired);
             Assert.IsTrue(DbTypeHelper.IsCompatible(c1.DataType, DbType.String));
         });
     }
 }