本文整理汇总了C#中FluentMigrator.Expressions.CreateTableExpression类的典型用法代码示例。如果您正苦于以下问题:C# CreateTableExpression类的具体用法?C# CreateTableExpression怎么用?C# CreateTableExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateTableExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了CreateTableExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCreateTableWithAutoIncrementExpression
public static CreateTableExpression GetCreateTableWithAutoIncrementExpression()
{
var expression = new CreateTableExpression { TableName = TestTableName1 };
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName1, IsIdentity = true, Type = DbType.Int32 });
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName2, Type = DbType.Int32 });
return expression;
}
示例2: GetCreateTableExpression
public static CreateTableExpression GetCreateTableExpression()
{
CreateTableExpression expression = new CreateTableExpression() { TableName = TestTableName1, };
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName1, Type = DbType.String });
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName2, Type = DbType.Int32 });
return expression;
}
示例3: ErrorIsReturnedWhenTableNameIsEmptyString
public void ErrorIsReturnedWhenTableNameIsEmptyString()
{
var expression = new CreateTableExpression { TableName = String.Empty };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
示例4: CanMigrateTableWithIdentityData
public void CanMigrateTableWithIdentityData()
{
// Arrange
var create = new CreateTableExpression
{
TableName = "Foo"
,
Columns = new List<ColumnDefinition> { new ColumnDefinition { Name = "Id", Type = DbType.Int32, IsIdentity = true} }
};
var context = GetDefaultContext();
var insert = new InsertDataExpression()
{
TableName = "Foo"
};
insert.Rows.Add(new InsertionDataDefinition { new KeyValuePair<string, object>("Id", 1)});
insert.Rows.Add(new InsertionDataDefinition { new KeyValuePair<string, object>("Id", 100) });
insert.WithIdentity = true;
// Act
MigrateTable(context, create, insert);
// Assert
context.MigrationIndex.ShouldBe(1);
}
示例5: ErrorIsNotReturnedWhenTableNameIsSet
public void ErrorIsNotReturnedWhenTableNameIsSet()
{
var expression = new CreateTableExpression { TableName = "table1" };
var errors = ValidationHelper.CollectErrors(expression);
Assert.That(errors.Count, Is.EqualTo(0));
}
示例6: GetCreateTableWithNullableColumn
public static CreateTableExpression GetCreateTableWithNullableColumn()
{
var expression = new CreateTableExpression { TableName = TestTableName1 };
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName1, IsNullable = true, Type = DbType.String });
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName2, Type = DbType.Int32 });
return expression;
}
示例7: Generate
public string Generate(CreateTableExpression expression)
{
IList<ColumnDefinition> columns = expression.Columns;
string result = "";
int total = columns.Count - 1;
//if more than one column is a primary key or the primary key is given a name, then it needs to be added separately
IList<ColumnDefinition> primaryKeyColumns = GetPrimaryKeyColumns(columns);
bool addPrimaryKeySeparately = false;
if (primaryKeyColumns.Count > 1 || (primaryKeyColumns.Count == 1 && !string.IsNullOrEmpty(primaryKeyColumns[0].PrimaryKeyName)))
{
if(CanSeperatePrimaryKeyAndIdentity || primaryKeyColumns.All(x => !x.IsIdentity))
{
addPrimaryKeySeparately = true;
foreach (ColumnDefinition column in primaryKeyColumns)
{
column.IsPrimaryKey = false;
}
}
}
for (int i = 0; i < columns.Count; i++)
{
result += Generate(columns[i]);
if (i != total)
result += ", ";
}
if (addPrimaryKeySeparately)
result = AddPrimaryKeyConstraint(expression.TableName, primaryKeyColumns, result);
return result;
}
示例8: GetCreateTableWithNamedMultiColumnPrimaryKeyExpression
public static CreateTableExpression GetCreateTableWithNamedMultiColumnPrimaryKeyExpression()
{
var expression = new CreateTableExpression { TableName = TestTableName1 };
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName1, IsPrimaryKey = true, PrimaryKeyName = "TestKey", Type = DbType.String });
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName2, Type = DbType.Int32, IsPrimaryKey = true });
return expression;
}
示例9: GetCreateTableWithDefaultValue
public static CreateTableExpression GetCreateTableWithDefaultValue()
{
CreateTableExpression expression = new CreateTableExpression() { TableName = TestTableName1, };
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName1, Type = DbType.String, DefaultValue = "Default", TableName = TestTableName1 });
expression.Columns.Add(new ColumnDefinition { Name = TestColumnName2, Type = DbType.Int32, DefaultValue = 0, TableName = TestTableName1 });
return expression;
}
示例10: GetCreateTableExpression
private CreateTableExpression GetCreateTableExpression(string tableName)
{
var columnName1 = "ColumnName1";
var column1 = new ColumnDefinition { Name = columnName1, Type = DbType.String };
var expression = new CreateTableExpression { TableName = tableName };
expression.Columns.Add(column1);
return expression;
}
示例11: CreateTableMigration
public dynamic CreateTableMigration(CreateTableMigration createTableMigration)
{
var create_table_expr = new CreateTableExpression
{
TableName = createTableMigration.TableName,
SchemaName = createTableMigration.SchemaName,
};
create_table_expr.Columns = createTableMigration.Colunns.Select(build_column_definition).ToList();
return create_table_expr;
}
示例12: CanCreateTableWithDateTimeOffsetColumn
public void CanCreateTableWithDateTimeOffsetColumn()
{
var expression = new CreateTableExpression {TableName = "TestTable1"};
expression.Columns.Add(new ColumnDefinition {TableName = "TestTable1", Name = "TestColumn1", Type = DbType.DateTimeOffset});
expression.Columns.Add(new ColumnDefinition {TableName = "TestTable1", Name = "TestColumn2", Type = DbType.DateTime2});
expression.Columns.Add(new ColumnDefinition {TableName = "TestTable1", Name = "TestColumn3", Type = DbType.Date});
expression.Columns.Add(new ColumnDefinition { TableName = "TestTable1", Name = "TestColumn4", Type = DbType.Time });
var result = Generator.Generate(expression);
result.ShouldBe("CREATE TABLE [dbo].[TestTable1] ([TestColumn1] DATETIMEOFFSET NOT NULL, [TestColumn2] DATETIME2 NOT NULL, [TestColumn3] DATE NOT NULL, [TestColumn4] TIME NOT NULL)");
}
示例13: Generate
public override string Generate(CreateTableExpression expression)
{
string FederatedOn = "";
if (!(string.IsNullOrEmpty(expression.Federation.DistributionName) || string.IsNullOrEmpty(expression.FederationColumn)))
{
FederatedOn = string.Format(FederateTable, expression.Federation.DistributionName,
expression.FederationColumn);
}
return Wrap(string.Format("{0} {1}", base.Generate(expression), FederatedOn));
}
示例14: Generate
public override string Generate(CreateTableExpression expression)
{
var descriptionStatements = DescriptionGenerator.GenerateDescriptionStatements(expression);
var createTableStatement = string.Format("CREATE TABLE {0}.{1}", Quoter.QuoteSchemaName(expression.SchemaName), base.Generate(expression));
var descriptionStatementsArray = descriptionStatements as string[] ?? descriptionStatements.ToArray();
if (!descriptionStatementsArray.Any())
return createTableStatement;
return ComposeStatements(createTableStatement, descriptionStatementsArray);
}
示例15: CanCreateTableExpression
public void CanCreateTableExpression()
{
CreateTableExpression expression = new CreateTableExpression { TableName = tableName };
expression.Columns.Add(column.Object);
using (command)
{
processor.Process(expression);
command.CommandText = string.Format("SELECT name FROM sqlite_master WHERE type='table' and name='{0}'", tableName);
command.ExecuteReader().Read().ShouldBeTrue();
}
}