本文整理汇总了C#中FluentMigrator.Expressions.UpdateDataExpression类的典型用法代码示例。如果您正苦于以下问题:C# UpdateDataExpression类的具体用法?C# UpdateDataExpression怎么用?C# UpdateDataExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UpdateDataExpression类属于FluentMigrator.Expressions命名空间,在下文中一共展示了UpdateDataExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
public void Initialize()
{
expression =
new UpdateDataExpression()
{
TableName = "ExampleTable",
Set = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("Column", "value")
},
IsAllRows = false
};
}
示例2: Generate
public abstract string Generate(UpdateDataExpression expression);
示例3: Generate
public override string Generate(UpdateDataExpression expression)
{
throw new NotImplementedException();
}
示例4: Generate
public override string Generate(UpdateDataExpression expression)
{
return string.Format("UPDATE {0}.{1}", Quoter.QuoteSchemaName(expression.SchemaName), base.Generate(expression));
}
示例5: Truncate
public void Truncate(UpdateDataExpression expression)
{
expression.TableName = Truncate(expression.TableName);
}
示例6: Generate
public override string Generate(UpdateDataExpression expression)
{
List<string> updateItems = new List<string>();
List<string> whereClauses = new List<string>();
foreach (var item in expression.Set)
{
updateItems.Add(string.Format("{0} = {1}", Quoter.QuoteColumnName(item.Key), Quoter.QuoteValue(item.Value)));
}
if(expression.IsAllRows)
{
whereClauses.Add("1 = 1");
}
else
{
foreach (var item in expression.Where)
{
whereClauses.Add(string.Format("{0} {1} {2}", Quoter.QuoteColumnName(item.Key),
item.Value == null ? "IS" : "=", Quoter.QuoteValue(item.Value)));
}
}
return String.Format(UpdateData, Quoter.QuoteTableName(expression.TableName), String.Join(", ", updateItems.ToArray()), String.Join(" AND ", whereClauses.ToArray()));
}
示例7: GetUpdateDataExpression
public static UpdateDataExpression GetUpdateDataExpression()
{
var expression = new UpdateDataExpression();
expression.TableName = TestTableName1;
expression.Set = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("Name", "Just'in"),
new KeyValuePair<string, object>("Age", 25)
};
expression.Where = new List<KeyValuePair<string, object>>
{
new KeyValuePair<string, object>("Id", 9),
new KeyValuePair<string, object>("Homepage", null)
};
return expression;
}
示例8: IfMigrationHasAnInvalidExpressionDuringUpActionShouldThrowAnExceptionAndAnnounceTheError
public void IfMigrationHasAnInvalidExpressionDuringUpActionShouldThrowAnExceptionAndAnnounceTheError()
{
var invalidMigration = new Mock<IMigration>();
var invalidExpression = new UpdateDataExpression {TableName = "Test"};
invalidMigration.Setup(m => m.GetUpExpressions(It.IsAny<IMigrationContext>())).Callback((IMigrationContext mc) => mc.Expressions.Add(invalidExpression));
Assert.Throws<InvalidMigrationException>(() => _runner.Up(invalidMigration.Object));
_announcer.Verify(a => a.Error(It.Is<string>(s => s.Contains("UpdateDataExpression: Update statement is missing a condition. Specify one by calling .Where() or target all rows by calling .AllRows()."))));
}
示例9: GetUpdateDataExpressionWithAllRows
public static UpdateDataExpression GetUpdateDataExpressionWithAllRows()
{
var expression = new UpdateDataExpression();
expression.TableName = TestTableName1;
expression.Set.AddRange(new[] { new ExplicitDataDefinition(new DataValue("Name", "Just'in"), new DataValue("Age", 25)) });
expression.IsAllRows = true;
return expression;
}
示例10: GetUpdateDataExpression
public static UpdateDataExpression GetUpdateDataExpression()
{
var expression = new UpdateDataExpression();
expression.TableName = TestTableName1;
expression.Set.AddRange(new [] { new ExplicitDataDefinition(new DataValue("Name", "Just'in"), new DataValue("Age", 25)) } );
expression.Where.AddRange(new [] { new ExplicitDataDefinition(new DataValue("Id", 9), new DataValue("Homepage", null)) } );
return expression;
}
示例11: Table
public IUpdateSetOrInSchemaSyntax Table(string tableName)
{
var expression = new UpdateDataExpression { TableName = tableName };
_context.Expressions.Add(expression);
return new UpdateDataExpressionBuilder(expression, _context);
}
示例12: Generate
public override string Generate(UpdateDataExpression expression)
{
return string.Format("UPDATE {0}", base.Generate(expression));
}
示例13: CanUpdateTable
public void CanUpdateTable()
{
CanInsertAndReadDataFromTestTable();
var expression = new UpdateDataExpression { TableName = "Foo"
, Set = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("Id", 2) }
, Where = new List<KeyValuePair<string, object>> { new KeyValuePair<string, object>("Id", 1) }
};
_processor.Process(expression);
var table = _processor.ReadTableData(string.Empty, "Foo");
1.ShouldBe(table.Tables[0].Rows.Count);
2.ShouldBe(table.Tables[0].Rows[0]["Id"]);
}
示例14: Generate
public override string Generate(UpdateDataExpression expression)
{
string setClause = EvaluateSet(expression.Set);
string whereClause = expression.IsAllRows ? "1 = 1" : EvaluateWhere(expression.Where);
return String.Format(UpdateData, Quoter.QuoteTableName(expression.TableName), setClause, whereClause, CommandDelimiter);
}
示例15: Truncate
public void Truncate(UpdateDataExpression expression)
{
expression.TableName = Truncate(expression.TableName);
List<KeyValuePair<string, object>> newSet = new List<KeyValuePair<string, object>>();
foreach (var data in expression.Set)
{
newSet.Add(new KeyValuePair<string, object>(Truncate(data.Key), data.Value));
}
expression.Set.Clear();
expression.Set.AddRange(newSet);
if (!expression.IsAllRows)
{
List<KeyValuePair<string, object>> newWhere = new List<KeyValuePair<string, object>>();
foreach (var data in expression.Where)
{
newWhere.Add(new KeyValuePair<string, object>(Truncate(data.Key), data.Value));
}
expression.Where.Clear();
expression.Where.AddRange(newWhere);
}
}