本文整理汇总了C#中FluentMigrator.Expressions.CreateIndexExpression类的典型用法代码示例。如果您正苦于以下问题:C# CreateIndexExpression类的具体用法?C# CreateIndexExpression怎么用?C# CreateIndexExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CreateIndexExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了CreateIndexExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
*/
}
示例2: ErrorIsReturnedWhenColumnCountIsZero
public void ErrorIsReturnedWhenColumnCountIsZero()
{
var expression = new CreateIndexExpression { Index = { Name = "IX", TableName = "test" } };
var errors = ValidationHelper.CollectErrors(expression);
errors.ShouldContain(ErrorMessages.IndexMustHaveOneOrMoreColumns);
}
示例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);
}
示例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());
}
示例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);
}
示例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;
}
示例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));
}
示例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();
}
示例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)");
}
示例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);
}
示例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);
}
示例12: Index
public ICreateIndexForTableSyntax Index(string indexName)
{
var expression = new CreateIndexExpression { Index = { Name = indexName } };
_context.Expressions.Add(expression);
return new CreateIndexExpressionBuilder(expression);
}
示例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);
}
示例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;
}
示例15: Process
public virtual void Process(CreateIndexExpression expression)
{
Process(Generator.Generate(expression));
}