本文整理汇总了C#中FluentMigrator.Expressions.CreateIndexExpression类的典型用法代码示例。如果您正苦于以下问题:C# CreateIndexExpression类的具体用法?C# CreateIndexExpression怎么用?C# CreateIndexExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateIndexExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了CreateIndexExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Generate
public override string Generate(CreateIndexExpression expression)
{
var result = new StringBuilder("CREATE");
if (expression.Index.IsUnique)
result.Append(" UNIQUE");
result.Append(" INDEX {0} ON {1}.{2} (");
var first = true;
foreach (var column in expression.Index.Columns)
{
if (first)
first = false;
else
result.Append(",");
result.Append("\"" + column.Name + "\"");
result.Append(column.Direction == Direction.Ascending ? " ASC" : " DESC");
}
result.Append(")");
return String.Format(result.ToString(), Quoter.QuoteIndexName(expression.Index.Name), Quoter.QuoteSchemaName(expression.Index.SchemaName), Quoter.QuoteTableName(expression.Index.TableName));
/*
var idx = String.Format(result.ToString(), expression.Index.Name, Quoter.QuoteSchemaName(expression.Index.SchemaName), expression.Index.TableName);
if (!expression.Index.IsClustered)
return idx;
// Clustered indexes in Postgres do not cluster updates/inserts to the table after the initial cluster operation is applied.
// To keep the clustered index up to date run CLUSTER TableName periodically
return string.Format("{0}; CLUSTER {1}\"{2}\" ON \"{3}\"", idx, Quoter.QuoteSchemaName(expression.Index.SchemaName), expression.Index.TableName, expression.Index.Name);
*/
}
开发者ID:robinvarg,项目名称:fluentmigrator,代码行数:34,代码来源:PostgresGenerator.cs
示例2: ErrorIsReturnedWhenColumnCountIsZero
public void ErrorIsReturnedWhenColumnCountIsZero()
{
var expression = new CreateIndexExpression { Index = { Name = "IX", TableName = "test" } };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.IndexMustHaveOneOrMoreColumns);
}
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:7,代码来源:CreateIndexExpressionTests.cs
示例3: Generate
public override string Generate(CreateIndexExpression expression)
{
var result = new StringBuilder("CREATE");
if (expression.Index.IsUnique)
result.Append(" UNIQUE");
//if (expression.Index.IsClustered)
// result.Append(" CLUSTERED");
//else
// result.Append(" NONCLUSTERED");
result.Append(" INDEX {0} ON {1} (");
bool first = true;
foreach (IndexColumnDefinition column in expression.Index.Columns)
{
if (first)
first = false;
else
result.Append(",");
result.Append(column.Name);
if (column.Direction == Direction.Ascending)
{
result.Append(" ASC");
}
else
{
result.Append(" DESC");
}
}
result.Append(")");
return String.Format(result.ToString(), expression.Index.Name, expression.Index.TableName);
}
开发者ID:jtreuting,项目名称:fluentmigrator,代码行数:35,代码来源:OracleGenerator.cs
示例4: Generate
public override string Generate(CreateIndexExpression expression)
{
//Firebird doesn't have particular asc or desc order per column, only per the whole index
// CREATE [UNIQUE] [ASC[ENDING] | [DESC[ENDING]] INDEX indexname
// ON tablename { (<col> [, <col> ...]) | COMPUTED BY (expression) }
// <col> ::= a column not of type ARRAY, BLOB or COMPUTED BY
//
// Assuming the first column's direction for the index's direction.
truncator.Truncate(expression);
StringBuilder indexColumns = new StringBuilder("");
Direction indexDirection = Direction.Ascending;
int columnCount = expression.Index.Columns.Count;
for (int i = 0; i < columnCount; i++)
{
IndexColumnDefinition columnDef = expression.Index.Columns.ElementAt(i);
if (i > 0)
indexColumns.Append(", ");
else indexDirection = columnDef.Direction;
indexColumns.Append(Quoter.QuoteColumnName(columnDef.Name));
}
return String.Format(CreateIndex
, GetUniqueString(expression)
, indexDirection == Direction.Ascending ? "ASC " : "DESC "
, Quoter.QuoteIndexName(expression.Index.Name)
, Quoter.QuoteTableName(expression.Index.TableName)
, indexColumns.ToString());
}
开发者ID:SaltyDH,项目名称:fluentmigrator,代码行数:33,代码来源:FirebirdGenerator.cs
示例5: ErrorIsReturnedWhenTableNameIsNull
public void ErrorIsReturnedWhenTableNameIsNull()
{
var expression = new CreateIndexExpression { Index = { Name = "IX", TableName = null } };
expression.Index.Columns.Add(new IndexColumnDefinition());
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.TableNameCannotBeNullOrEmpty);
}
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:8,代码来源:CreateIndexExpressionTests.cs
示例6: GetCreateIndexExpression
public static CreateIndexExpression GetCreateIndexExpression()
{
var expression = new CreateIndexExpression();
expression.Index.Name = TestIndexName;
expression.Index.TableName = TestTableName1;
expression.Index.IsUnique = false;
expression.Index.Columns.Add(new IndexColumnDefinition { Direction = Direction.Ascending, Name = TestColumnName1 });
return expression;
}
开发者ID:rmmason,项目名称:fluentmigrator,代码行数:9,代码来源:GeneratorTestHelper.cs
示例7: ErrorIsNotReturnedWhenValidExpression
public void ErrorIsNotReturnedWhenValidExpression()
{
var expression = new CreateIndexExpression { Index = { Name = "IX", TableName = "test" } };
expression.Index.Columns.Add(new IndexColumnDefinition{ Name = "Column1"});
var errors = ValidationHelper.CollectErrors(expression);
Assert.That(errors.Count, Is.EqualTo(0));
}
开发者ID:BarsBarsovich,项目名称:fluentmigrator,代码行数:9,代码来源:CreateIndexExpressionTests.cs
示例8: ShouldDelegateApplyConventionsToIndexDefinition
public void ShouldDelegateApplyConventionsToIndexDefinition()
{
var definitionMock = new Mock<IndexDefinition>();
var createIndexExpression = new CreateIndexExpression {Index = definitionMock.Object};
var migrationConventions = new Mock<IMigrationConventions>(MockBehavior.Strict).Object;
definitionMock.Setup(id => id.ApplyConventions(migrationConventions)).Verifiable();
createIndexExpression.ApplyConventions(migrationConventions);
definitionMock.VerifyAll();
}
开发者ID:rebootd,项目名称:fluentmigrator,代码行数:12,代码来源:CreateIndexExpressionTests.cs
示例9: CanCreateIndex
public void CanCreateIndex()
{
var expression = new CreateIndexExpression();
expression.Index.Name = "IX_TEST";
expression.Index.TableName = "TEST_TABLE";
expression.Index.IsUnique = true;
expression.Index.IsClustered = true;
expression.Index.Columns.Add(new IndexColumnDefinition { Direction = Direction.Ascending, Name = "Column1" });
expression.Index.Columns.Add(new IndexColumnDefinition { Direction = Direction.Descending, Name = "Column2" });
string sql = generator.Generate(expression);
sql.ShouldBe("CREATE UNIQUE CLUSTERED INDEX IX_TEST ON TEST_TABLE (Column1 ASC,Column2 DESC)");
}
开发者ID:stevehodgkiss,项目名称:fluentmigrator,代码行数:13,代码来源:SqlServerGeneratorTests.cs
示例10: CanCreateAcendingIndex
public void CanCreateAcendingIndex()
{
// Arrange
var columns = new List<ColumnDefinition> {new ColumnDefinition {Name = "Data", Type = DbType.String}};
var index = new CreateIndexExpression { Index = new IndexDefinition { Name = "IDX_Foo", TableName = "Foo" } };
index.Index.Columns.Add(new IndexColumnDefinition { Name = "Data", Direction = Direction.Ascending});
// Act
var table = CreateTable(columns, index);
// Assert
table.Indexes.Count.ShouldBe(1);
table.Indexes.First().Name.ShouldBe("IDX_FOO");
table.Indexes.First().Columns.Count.ShouldBe(1);
table.Indexes.First().Columns.First().Name.ShouldBe("DATA");
table.Indexes.First().Columns.First().Direction.ShouldBe(Direction.Ascending);
}
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:18,代码来源:OracleDumpTableIndexesTests.cs
示例11: CanCreateCompositeIndex
public void CanCreateCompositeIndex()
{
// Arrange
var columns = new List<ColumnDefinition>
{
new ColumnDefinition { Name = "Data", Type = DbType.String }
, new ColumnDefinition { Name = "Data2", Type = DbType.String }
};
var index = new CreateIndexExpression { Index = new IndexDefinition { Name = "IDX_Foo", TableName = "Foo", IsUnique = true } };
index.Index.Columns.Add(new IndexColumnDefinition { Name = "Data" });
index.Index.Columns.Add(new IndexColumnDefinition { Name = "Data2" });
// Act
var table = CreateTable(columns, index);
// Assert
table.Indexes.First().Columns.Count.ShouldBe(2);
}
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:19,代码来源:OracleDumpTableIndexesTests.cs
示例12: Index
public ICreateIndexForTableSyntax Index(string indexName)
{
var expression = new CreateIndexExpression { Index = { Name = indexName } };
_context.Expressions.Add(expression);
return new CreateIndexExpressionBuilder(expression);
}
开发者ID:fire-eagle,项目名称:fluentmigrator,代码行数:6,代码来源:CreateExpressionRoot.cs
示例13: Generate
public override string Generate(CreateIndexExpression expression)
{
var result = new StringBuilder("CREATE");
if (expression.Index.IsUnique)
result.Append(" UNIQUE");
result.Append(" INDEX IF NOT EXISTS {0} ON {1} (");
bool first = true;
foreach (IndexColumnDefinition column in expression.Index.Columns)
{
if (first)
first = false;
else
result.Append(",");
result.Append(column.Name);
}
result.Append(")");
return FormatExpression(result.ToString(), expression.Index.Name, expression.Index.TableName);
}
开发者ID:paulbatum,项目名称:fluentmigrator,代码行数:22,代码来源:SqliteGenerator.cs
示例14: GetClusterTypeString
//Not need for the nonclusted keyword as it is the default mode
public override string GetClusterTypeString(CreateIndexExpression column)
{
return column.Index.IsClustered ? "CLUSTERED " : string.Empty;
}
开发者ID:kramerpr,项目名称:fluentmigrator,代码行数:5,代码来源:SqlServer2000Generator.cs
示例15: Process
public virtual void Process(CreateIndexExpression expression)
{
Process(Generator.Generate(expression));
}
开发者ID:Ang3lFir3,项目名称:fluentmigrator,代码行数:4,代码来源:ProcessorBase.cs
示例16: CanForeignKeyToUniqueColumn
public void CanForeignKeyToUniqueColumn()
{
// Arrange
var create = new CreateTableExpression
{
TableName = "Foo",
Columns = new[]{
new ColumnDefinition {Name = "Id", Type = DbType.Int32, IsPrimaryKey = true}
, new ColumnDefinition {Name = "Type", Type = DbType.Int32}
}
};
var index = new CreateIndexExpression
{
Index =
new IndexDefinition()
{
Name = "IDX_FooType",
TableName = "Foo",
IsUnique = true,
Columns = new List<IndexColumnDefinition> { new IndexColumnDefinition { Name = "Type" } }
}
};
var secondTable = new CreateTableExpression
{
TableName = "Bar",
Columns = new[]{
new ColumnDefinition {Name = "Id", Type = DbType.Int32, IsPrimaryKey = true}
, new ColumnDefinition {Name = "FooType", Type = DbType.Int32}
}
};
var foreignKey = new CreateForeignKeyExpression
{
ForeignKey =
new ForeignKeyDefinition()
{
Name = "FK_FooType",
ForeignTable = "Bar",
ForeignColumns = new [] { "FooType" },
PrimaryTable= "Foo",
PrimaryColumns = new[] { "Type" }
}
};
// Act
MigrateToOracleWithData(new List<IMigrationExpression> { create, index, secondTable, foreignKey }, 2);
// Assert
}
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:52,代码来源:SqlServerToOracleMigrationTests.cs
示例17: Indexed
public virtual void Indexed(string indexName)
{
_builder.Column.IsIndexed = true;
var index = new CreateIndexExpression
{
Index = new IndexDefinition
{
Name = indexName,
SchemaName = _builder.SchemaName,
TableName = _builder.TableName
}
};
index.Index.Columns.Add(new IndexColumnDefinition
{
Name = _builder.Column.Name
});
_context.Expressions.Add(index);
}
开发者ID:BhuvanB,项目名称:fluentmigrator,代码行数:21,代码来源:ColumnExpressionBuilderHelper.cs
示例18: CanCreateUniqueIndex
public void CanCreateUniqueIndex()
{
var expression = new CreateIndexExpression();
expression.Index.Name = "IX_TEST";
expression.Index.TableName = "TEST_TABLE";
expression.Index.IsUnique = true;
expression.Index.Columns.Add(new IndexColumnDefinition { Direction = Direction.Ascending, Name = "Column1" });
expression.Index.Columns.Add(new IndexColumnDefinition { Direction = Direction.Descending, Name = "Column2" });
string sql = generator.Generate(expression);
sql.ShouldBe("CREATE UNIQUE INDEX \"IX_TEST\" ON \"public\".\"TEST_TABLE\" (\"Column1\" ASC,\"Column2\" DESC)");
}
开发者ID:timscott,项目名称:fluentmigrator,代码行数:12,代码来源:PostgresGeneratorTests.cs
示例19: Generate
public abstract string Generate(CreateIndexExpression expression);
开发者ID:ibebbs,项目名称:fluentmigrator,代码行数:1,代码来源:GeneratorBase.cs
示例20: CanMigrateTableAndIndexWithOneColumnNameCaseSensitive
public void CanMigrateTableAndIndexWithOneColumnNameCaseSensitive()
{
// Arrange
var create = new CreateTableExpression
{
TableName = "Foo",
Columns = new[]{
new ColumnDefinition {Name = "id", Type = DbType.Int32}
, new ColumnDefinition {Name = "Data", Type = DbType.Int32}
}
};
var index = new CreateIndexExpression()
{
Index =
new IndexDefinition()
{
Name = "IDX_id",
TableName = "Foo",
Columns = new[] {new IndexColumnDefinition {Name = "id"}}
}
};
// Act
var context = GetDefaultContext();
context.CaseSenstiveColumns.Add("id");
context.PreMigrationTableUpdate = tables =>
{
tables.First().Columns.First().Name = "\\\"id\\\"";
tables.First().Indexes.First().Columns.First().Name = "\\\"id\\\"";
};
CreateTables(create);
CreateIndexes(index);
MigrateTable(context);
// Assert
}
开发者ID:garchibald,项目名称:fluentmigrator,代码行数:41,代码来源:SqlServerToOracleMigrationTests.cs
注:本文中的FluentMigrator.Expressions.CreateIndexExpression类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论