本文整理汇总了C#中Migrator.Framework.Column类的典型用法代码示例。如果您正苦于以下问题:C# Column类的具体用法?C# Column怎么用?C# Column使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Column类属于Migrator.Framework命名空间,在下文中一共展示了Column类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ChangeColumn
public override void ChangeColumn(string table, Column column)
{
if (!ColumnExists(table, column.Name))
{
Logger.Warn("Column {0}.{1} does not exist", table, column.Name);
return;
}
var existingColumn = GetColumnByName(table, column.Name);
column.Name = existingColumn.Name; // name might have different case.
string tempColumn = "temp_" + column.Name;
RenameColumn(table, column.Name, tempColumn);
// check if this is not-null
bool isNotNull = (column.ColumnProperty & ColumnProperty.NotNull) == ColumnProperty.NotNull;
// remove the not-null option
column.ColumnProperty = (column.ColumnProperty & ~ColumnProperty.NotNull);
AddColumn(table, column);
ExecuteQuery(String.Format("UPDATE {0} SET {1}={2}", table, Dialect.Quote(column.Name), tempColumn));
RemoveColumn(table, tempColumn);
// if is not null, set that now
if (isNotNull) ExecuteQuery(string.Format("ALTER TABLE {0} ALTER COLUMN {1} SET NOT NULL", table, Dialect.Quote(column.Name)));
}
示例2: Up
public override void Up()
{
var col = new Column("Url", DbType.String, 255, ColumnProperty.Null);
foreach (string table in _tables)
Database.AddColumn(table, col);
}
示例3: MapColumnProperties
public override void MapColumnProperties(Column column)
{
Name = column.Name;
indexed = PropertySelected(column.ColumnProperty, ColumnProperty.Indexed);
var vals = new List<string>();
AddName(vals);
AddType(vals);
AddIdentity(column, vals);
AddUnsigned(column, vals);
AddPrimaryKey(column, vals);
AddIdentityAgain(column, vals);
AddUnique(column, vals);
AddForeignKey(column, vals);
AddDefaultValue(column, vals);
// null / not-null comes last on Oracle - otherwise if use Null/Not-null + default, bad things happen
// (http://geekswithblogs.net/faizanahmad/archive/2009/08/07/add-new-columnfield-in-oracle-db-table---ora.aspx)
AddNotNull(column, vals);
AddNull(column, vals);
columnSql = String.Join(" ", vals.ToArray());
}
示例4: IndexKeyColumn
public IndexKeyColumn(Column column, SortDirection sortDirection)
{
if (column == null) throw new ArgumentNullException("column");
Column = column;
SortDirection = sortDirection;
}
示例5: MapColumnProperties
public void MapColumnProperties(Column column)
{
Name = column.Name;
indexed = PropertySelected(column.ColumnProperty, ColumnProperty.Indexed);
List<string> vals = new List<string>();
vals.Add(dialect.ColumnNameNeedsQuote ? QuotedName : Name);
vals.Add(type);
if (! dialect.IdentityNeedsType)
AddValueIfSelected(column, ColumnProperty.Identity, vals);
AddValueIfSelected(column, ColumnProperty.Unsigned, vals);
if (! PropertySelected(column.ColumnProperty, ColumnProperty.PrimaryKey) || dialect.NeedsNotNullForIdentity)
AddValueIfSelected(column, ColumnProperty.NotNull, vals);
AddValueIfSelected(column, ColumnProperty.PrimaryKey, vals);
if (dialect.IdentityNeedsType)
AddValueIfSelected(column, ColumnProperty.Identity, vals);
AddValueIfSelected(column, ColumnProperty.Unique, vals);
AddValueIfSelected(column, ColumnProperty.ForeignKey, vals);
if (column.DefaultValue != null)
vals.Add(dialect.Default(column.DefaultValue));
columnSql = String.Join(" ", vals.ToArray());
}
示例6: MapColumnProperties
public virtual void MapColumnProperties(Column column)
{
Name = column.Name;
indexed = PropertySelected(column.ColumnProperty, ColumnProperty.Indexed);
var vals = new List<string>();
AddName(vals);
AddType(vals);
AddIdentity(column, vals);
AddUnsigned(column, vals);
AddNotNull(column, vals);
AddNull(column, vals);
AddPrimaryKey(column, vals);
AddIdentityAgain(column, vals);
AddUnique(column, vals);
AddForeignKey(column, vals);
AddDefaultValue(column, vals);
columnSql = String.Join(" ", vals.ToArray());
}
示例7: GetColumnMapper
public ColumnPropertiesMapper GetColumnMapper(Column column)
{
string type = column.Size > 0 ? GetTypeName(column.Type, column.Size) : GetTypeName(column.Type);
if (! IdentityNeedsType && column.IsIdentity)
type = String.Empty;
return new ColumnPropertiesMapper(this, type);
}
示例8: GetAndMapColumnProperties
public ColumnPropertiesMapper GetAndMapColumnProperties(Column column)
{
ColumnPropertiesMapper mapper = GetColumnMapper(column);
mapper.MapColumnProperties(column);
if (column.DefaultValue != null)
mapper.Default = column.DefaultValue;
return mapper;
}
示例9: Int32_is_unsigned_compatible
public void Int32_is_unsigned_compatible()
{
//arange
Column column = new Column("test", DbType.Int32, ColumnProperty.Unsigned);
//act
ColumnPropertiesMapper mapper = _dialect.GetAndMapColumnProperties(column);
//assert
StringAssert.Contains("UNSIGNED", mapper.ColumnSql);
}
示例10: Guid_is_not_unsigned_compatible
public void Guid_is_not_unsigned_compatible()
{
//arrange
Column column = new Column("test", DbType.Guid, ColumnProperty.Unsigned);
//act
ColumnPropertiesMapper mapper = _dialect.GetAndMapColumnProperties(column);
//assert
Assert.IsFalse(mapper.ColumnSql.Contains("UNSIGNED"));
}
示例11: MergeNameWithStandardFields
public static Column[] MergeNameWithStandardFields(string indicatedName, Column nameColumn)
{
return new[]
{
new Column(CreatePrimaryKeyColumnName(indicatedName), DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
nameColumn,
new Column("Depricated", DbType.Boolean, ColumnProperty.NotNull, 0),
new Column("IsDeleted", DbType.Boolean, ColumnProperty.Null, 0),
new Column("CreatedBy", DbType.Int32, ColumnProperty.NotNull),
new Column("CreatedDate", DbType.DateTime, ColumnProperty.NotNull, "(getdate())")
};
}
示例12: ChangeColumn
public override void ChangeColumn(string table, Column column)
{
if (!ColumnExists(table, column.Name))
{
Logger.Warn("Column {0}.{1} does not exist", table, column.Name);
return;
}
var existingColumn = GetColumnByName(table, column.Name);
if (column.Type == DbType.String)
{
RenameColumn(table, column.Name, TemporaryColumnName);
// check if this is not-null
bool isNotNull = (column.ColumnProperty & ColumnProperty.NotNull) == ColumnProperty.NotNull;
// remove the not-null option
column.ColumnProperty = (column.ColumnProperty & ~ColumnProperty.NotNull);
AddColumn(table, column);
CopyDataFromOneColumnToAnother(table, TemporaryColumnName, column.Name);
RemoveColumn(table, TemporaryColumnName);
//RenameColumn(table, TemporaryColumnName, column.Name);
string columnName = QuoteColumnNameIfRequired(column.Name);
// now set the column to not-null
if (isNotNull) ExecuteQuery(String.Format("ALTER TABLE {0} MODIFY ({1} NOT NULL)", table, columnName));
}
else
{
if (((existingColumn.ColumnProperty & ColumnProperty.NotNull) == ColumnProperty.NotNull)
&& ((column.ColumnProperty & ColumnProperty.NotNull) == ColumnProperty.NotNull))
{
// was not null, and is being change to not-null - drop the not-null all together
column.ColumnProperty = column.ColumnProperty & ~ColumnProperty.NotNull;
}
else if
(((existingColumn.ColumnProperty & ColumnProperty.Null) == ColumnProperty.Null)
&& ((column.ColumnProperty & ColumnProperty.Null) == ColumnProperty.Null))
{
// was null, and is being changed to null - drop the null all together
column.ColumnProperty = column.ColumnProperty & ~ColumnProperty.Null;
}
ColumnPropertiesMapper mapper = _dialect.GetAndMapColumnProperties(column);
ChangeColumn(table, mapper.ColumnSql);
}
}
示例13: ChangeColumn
public override void ChangeColumn(string table, Column column)
{
if (!ColumnExists(table, column.Name))
{
Logger.Warn("Column {0}.{1} does not exist", table, column.Name);
return;
}
string tempColumn = "temp_" + column.Name;
RenameColumn(table, column.Name, tempColumn);
AddColumn(table, column);
ExecuteQuery(String.Format("UPDATE {0} SET {1}={2}", table, column.Name, tempColumn));
RemoveColumn(table, tempColumn);
}
示例14: Up
public override void Up()
{
Column[] columns = new Column[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
new Column("TaskId", DbType.Int32,
ColumnProperty.ForeignKey | ColumnProperty.NotNull),
new Column("Estimate", DbType.Double, ColumnProperty.NotNull),
new Column("Timestamp", DbType.DateTime, ColumnProperty.NotNull)
};
Database.AddTable("TaskEstimateHistory", columns);
Database.AddForeignKey("FK_TaskEstimateHistory_Task", "TaskEstimateHistory", "TaskId", "Tasks", "Id", ForeignKeyConstraint.Cascade);
}
示例15: Up
public override void Up()
{
Column[] columns = new Column[]
{
new Column("Id", DbType.Int32, ColumnProperty.PrimaryKeyWithIdentity),
new Column("Name", DbType.String, 255, ColumnProperty.NotNull),
new Column("Description", DbType.String),
new Column("BusinessValue", DbType.Int32),
new Column("Priority", DbType.Int32),
new Column("Estimate", DbType.Int32),
new Column("ProjectId", DbType.Int32, ColumnProperty.ForeignKey | ColumnProperty.NotNull),
};
Database.AddTable("Stories", columns);
Database.AddForeignKey("FK_Stories_Project", "Stories", "ProjectId", "Projects", "Id", ForeignKeyConstraint.Cascade);
}