本文整理汇总了C#中FluentMigrator.Expressions.InsertDataExpression类的典型用法代码示例。如果您正苦于以下问题:C# InsertDataExpression类的具体用法?C# InsertDataExpression怎么用?C# InsertDataExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InsertDataExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了InsertDataExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: UpdateVersionInfo
public void UpdateVersionInfo(long version, string description)
{
var dataExpression = new InsertDataExpression();
dataExpression.Rows.Add(CreateVersionInfoInsertionData(version, description));
dataExpression.TableName = VersionTableMetaData.TableName;
dataExpression.SchemaName = VersionTableMetaData.SchemaName;
dataExpression.ExecuteWith(Processor);
}
示例3: Reverse
public IMigrationExpression Reverse()
{
var expression = new InsertDataExpression
{
SchemaName = SchemaName,
TableName = TableName
};
expression.Rows.AddRange(Rows);
return expression;
}
示例4: ExplicitUnicodeStringIgnoredForNonSqlServer
public void ExplicitUnicodeStringIgnoredForNonSqlServer()
{
var expression = new InsertDataExpression {TableName = "TestTable"};
expression.Rows.Add(new InsertionDataDefinition
{
new KeyValuePair<string, object>("NormalString", "Just'in"),
new KeyValuePair<string, object>("UnicodeString", new ExplicitUnicodeString("codethinked'.com"))
});
var result = Generator.Generate(expression);
result.ShouldBe("INSERT INTO \"public\".\"TestTable\" (\"NormalString\",\"UnicodeString\") VALUES ('Just''in','codethinked''.com');");
}
示例5: CanInsertAtAtIdentity
public void CanInsertAtAtIdentity()
{
var expression = new InsertDataExpression {TableName = "TestTable"};
expression.Rows.Add(new InsertionDataDefinition
{
new KeyValuePair<string, object>("Id", 1),
new KeyValuePair<string, object>("Name", RawSql.Insert("@@IDENTITY")),
new KeyValuePair<string, object>("Website", "codethinked.com")
});
var result = Generator.Generate(expression);
result.ShouldBe("INSERT INTO [dbo].[TestTable] ([Id], [Name], [Website]) VALUES (1, @@IDENTITY, 'codethinked.com')");
}
示例6: ExplicitUnicodeQuotesCorrectly
public void ExplicitUnicodeQuotesCorrectly()
{
var expression = new InsertDataExpression {TableName = "TestTable"};
expression.Rows.Add(new InsertionDataDefinition
{
new KeyValuePair<string, object>("UnicodeStringValue", new ExplicitUnicodeString("UnicodeString")),
new KeyValuePair<string, object>("StringValue", "AnsiiString")
});
var result = Generator.Generate(expression);
result.ShouldBe("INSERT INTO [dbo].[TestTable] ([UnicodeStringValue], [StringValue]) VALUES (N'UnicodeString', 'AnsiiString')");
}
示例7: Generate
public override string Generate(InsertDataExpression expression)
{
var insertStrings = new List<string>();
foreach (IDataDefinition row in expression.Rows)
{
IEnumerable<IDataValue> dataValues = evaluator.Evaluate(row).ToArray();
string columns = String.Join(", ", dataValues.Select(dataValue => Quoter.QuoteColumnName(dataValue.ColumnName)).ToArray());
string values = String.Join(", ", dataValues.Select(dataValue => Quoter.QuoteDataValue(dataValue)).ToArray());
insertStrings.Add(String.Format(InsertData, Quoter.QuoteTableName(expression.TableName), columns, values, CommandDelimiter));
}
return "INSERT ALL " + String.Join(" ", insertStrings.ToArray()) + " SELECT 1 FROM DUAL";
}
示例8: Reverse
public IMigrationExpression Reverse()
{
var expression = new InsertDataExpression
{
SchemaName = SchemaName,
TableName = TableName
};
foreach (var row in Rows)
{
var dataDefinition = new InsertionDataDefinition();
dataDefinition.AddRange(row);
expression.Rows.Add(dataDefinition);
}
return expression;
}
示例9: Generate
public override string Generate(InsertDataExpression expression)
{
var columnNames = new List<string>();
var columnValues = new List<string>();
var insertStrings = new List<string>();
foreach (InsertionDataDefinition row in expression.Rows)
{
columnNames.Clear();
columnValues.Clear();
foreach (KeyValuePair<string, object> item in row)
{
columnNames.Add(Quoter.QuoteColumnName(item.Key));
columnValues.Add(Quoter.QuoteValue(item.Value));
}
string columns = String.Join(", ", columnNames.ToArray());
string values = String.Join(", ", columnValues.ToArray());
insertStrings.Add(String.Format(InsertData, Quoter.QuoteTableName(expression.TableName), columns, values));
}
return "INSERT ALL " + String.Join(" ", insertStrings.ToArray()) + " SELECT 1 FROM DUAL";
}
示例10: CanInsertBinaryData
public void CanInsertBinaryData()
{
var expression = new InsertDataExpression
{
TableName = "TestTable1"
};
var row1 = new { Id = 1, Name = "Just'in", Value = Encoding.ASCII.GetBytes("Just'in") };
var row2 = new { Id = 1, Name = "Na\te", Value = Encoding.ASCII.GetBytes("Na\te") };
expression.Rows.AddRange(new IDataDefinition[]
{
new ReflectedDataDefinition(row1),
new ReflectedDataDefinition(row2)
}
);
var sql = generator.Generate(expression);
var expected = "INSERT INTO `TestTable1` (`Id`, `Name`, `Value`) VALUES (1, 'Just''in', UNHEX('4A75737427696E'));";
expected += "\r\nINSERT INTO `TestTable1` (`Id`, `Name`, `Value`) VALUES (1, 'Na e', UNHEX('4E610965'));";
sql.ShouldBe(expected);
}
示例11: CanInsertGuidData
public void CanInsertGuidData()
{
var gid = Guid.NewGuid();
var expression = new InsertDataExpression { TableName = "TestTable" };
expression.Rows.Add(new ExplicitDataDefinition(new DataValue("guid", gid)));
var sql = generator.Generate(expression);
var expected = String.Format("INSERT INTO \"public\".\"TestTable\" (\"guid\") VALUES ('{0}');", gid);
sql.ShouldBe(expected);
}
示例12: UpdateVersionInfo
public void UpdateVersionInfo(long version, Type type, TimeSpan elapsedTime)
{
var dataExpression = new InsertDataExpression();
dataExpression.Rows.Add( CreateVersionInfoInsertionData( version, type, elapsedTime ) );
dataExpression.TableName = VersionTableMetaData.TableName;
dataExpression.SchemaName = VersionTableMetaData.SchemaName;
dataExpression.ExecuteWith( Processor );
}
示例13: Generate
public override string Generate(InsertDataExpression expression)
{
var result = new StringBuilder();
foreach (var row in expression.Rows)
{
var columnNames = new List<string>();
var columnData = new List<object>();
foreach (var item in row)
{
columnNames.Add(item.Key);
columnData.Add(item.Value);
}
var columns = GetColumnList(columnNames);
var data = GetDataList(columnData);
result.Append(String.Format("INSERT INTO {0}.{1} ({2}) VALUES ({3});", Quoter.QuoteSchemaName(expression.SchemaName), Quoter.QuoteTableName(expression.TableName), columns, data));
}
return result.ToString();
}
示例14: Generate
public override string Generate(InsertDataExpression expression)
{
if (IsUsingIdentityInsert(expression))
{
return string.Format("{0}; {1}; {2}",
string.Format(IdentityInsert, Quoter.QuoteTableName(expression.TableName), "ON"),
base.Generate(expression),
string.Format(IdentityInsert, Quoter.QuoteTableName(expression.TableName), "OFF"));
}
return base.Generate(expression);
}
示例15: IsUsingIdentityInsert
protected static bool IsUsingIdentityInsert(InsertDataExpression expression)
{
if (expression.AdditionalFeatures.ContainsKey(SqlServerExtensions.IdentityInsert))
{
return (bool)expression.AdditionalFeatures[SqlServerExtensions.IdentityInsert];
}
return false;
}