本文整理汇总了C#中FluentMigrator.Model.ColumnDefinition类的典型用法代码示例。如果您正苦于以下问题:C# ColumnDefinition类的具体用法?C# ColumnDefinition怎么用?C# ColumnDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ColumnDefinition类属于FluentMigrator.Model命名空间,在下文中一共展示了ColumnDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatNullable
protected override string FormatNullable(ColumnDefinition column)
{
if (column.IsNullable.GetValueOrDefault())
return column.ModificationType == ColumnModificationType.Alter ? "NULL" : string.Empty;
return "NOT NULL";
}
示例2: ColumnTypesMatch
public static bool ColumnTypesMatch(ColumnDefinition col1, ColumnDefinition col2)
{
FirebirdColumn column = new FirebirdColumn(new FirebirdOptions());
string colDef1 = column.GenerateForTypeAlter(col1);
string colDef2 = column.GenerateForTypeAlter(col2);
return colDef1 == colDef2;
}
示例3: WriteColumn
protected void WriteColumn(ColumnDefinition column, StreamWriter output, bool isLastColumn)
{
string columnSyntax = ".WithColumn(\"" + column.Name + "\")";
switch (column.Type)
{
case DbType.Boolean:
columnSyntax += ".AsBoolean()";
break;
case DbType.Int16:
columnSyntax += ".AsInt16()";
break;
case DbType.Int32:
columnSyntax += ".AsInt32()";
break;
default:
columnSyntax += ".AsString()";
break;
}
if (column.IsIdentity)
columnSyntax += ".Identity()";
else if (column.IsIndexed)
columnSyntax += ".Indexed()";
if (column.IsNullable == false)
columnSyntax += ".NotNullable()";
if (isLastColumn) columnSyntax += ";";
output.WriteLine("\t\t\t\t" + columnSyntax);
}
示例4: GenerateAlterClause
public string GenerateAlterClause(ColumnDefinition column)
{
if (column.IsIdentity)
{
throw new NotSupportedException("Altering an identity column is not supported.");
}
var alterClauses = AlterClauseOrder.Aggregate(new StringBuilder(), (acc, newRow) =>
{
var clause = newRow(column);
if (acc.Length == 0)
{
acc.Append(newRow(column));
}
else if (!string.IsNullOrEmpty(clause))
{
acc.Append(clause.PadLeft(clause.Length + 1));
}
return acc;
});
return string.Format(
"ALTER COLUMN {0} SET DATA TYPE {1}",
Quoter.QuoteColumnName(column.Name),
alterClauses);
}
示例5: GenerateDDLForColumn
public virtual string GenerateDDLForColumn(ColumnDefinition column)
{
var sb = new StringBuilder();
sb.Append(column.Name);
sb.Append(" ");
sb.Append(GetTypeMap(column.Type.Value, column.Size, column.Precision));
if (!column.IsNullable)
{
sb.Append(" NOT NULL");
}
if (column.DefaultValue != null)
{
sb.Append(" DEFAULT ");
sb.Append(GetConstantValue(column.DefaultValue));
}
if (column.IsIdentity)
{
sb.Append(" IDENTITY(1,1)");
}
if (column.IsPrimaryKey)
{
sb.Append(" PRIMARY KEY CLUSTERED");
}
return sb.ToString();
}
示例6: FormatType
protected override string FormatType(ColumnDefinition column)
{
if (column.IsIdentity)
return GetTypeMap(DbType.Int32, column.Size, column.Precision);
return base.FormatType(column);
}
示例7: FormatType
protected virtual string FormatType(ColumnDefinition column)
{
if (!column.Type.HasValue)
return column.CustomType;
return GetTypeMap(column.Type.Value, column.Size, column.Precision);
}
示例8: Truncate
public void Truncate(ColumnDefinition column)
{
column.Name = Truncate(column.Name);
column.TableName = Truncate(column.TableName);
if (column.IsPrimaryKey)
column.PrimaryKeyName = packKeyNames ? Pack(column.PrimaryKeyName) : Truncate(column.PrimaryKeyName);
}
示例9: FormatIdentity
protected override string FormatIdentity(ColumnDefinition column)
{
if (column.IsIdentity)
{
//todo: would like to throw a warning here
}
return string.Empty;
}
示例10: CanAddColumnWithGetDateDefault
public void CanAddColumnWithGetDateDefault()
{
ColumnDefinition column = new ColumnDefinition { Name = "TestColumn1", Type = DbType.String,
Size = 5, DefaultValue = "GetDate()" };
var expression = new CreateColumnExpression { TableName = "TestTable1", Column = column };
var sql = _generator.Generate(expression);
sql.ShouldBe("ALTER TABLE [TestTable1] ADD [TestColumn1] NVARCHAR(5) NOT NULL DEFAULT GetDate()");
}
示例11: FormatPrimaryKey
protected override string FormatPrimaryKey(ColumnDefinition column)
{
if (!column.IsPrimaryKey)
return string.Empty;
//Assume that if its IDENTITY and PRIMARY KEY, the it should be an AUTOINCREMENT column
return !column.IsIdentity ? "PRIMARY KEY" : "PRIMARY KEY AUTOINCREMENT";
}
示例12: CanUseSystemMethodCurrentDateTimeAsADefaultValueForAColumn
public void CanUseSystemMethodCurrentDateTimeAsADefaultValueForAColumn()
{
var columnDefinition = new ColumnDefinition { Name = "NewColumn", Size = 15, Type = null, CustomType = "TIMESTAMP", DefaultValue = SystemMethods.CurrentDateTime };
var expression = new CreateColumnExpression { Column = columnDefinition, TableName = "NewTable" };
var result = Generator.Generate(expression);
result.ShouldBe("ALTER TABLE `NewTable` ADD COLUMN `NewColumn` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP");
}
示例13: FormatIdentity
protected override string FormatIdentity(ColumnDefinition column)
{
if (column.IsIdentity)
{
throw new DatabaseOperationNotSupportedException("Oracle does not support identity columns. Please use a SEQUENCE instead");
}
return string.Empty;
}
示例14: FormatDefaultValue
protected override string FormatDefaultValue(ColumnDefinition column)
{
var defaultValue = base.FormatDefaultValue(column);
if(!string.IsNullOrEmpty(defaultValue))
return string.Format("CONSTRAINT DF_{0}_{1} ", column.TableName, column.Name) + defaultValue;
return string.Empty;
}
示例15: FormatNullable
protected virtual string FormatNullable(ColumnDefinition column)
{
if (column.IsNullable.HasValue && column.IsNullable.Value) {
return string.Empty;
}
else {
return "NOT NULL";
}
}