本文整理汇总了C#中SimpleExpression.GetOperandsOfType方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleExpression.GetOperandsOfType方法的具体用法?C# SimpleExpression.GetOperandsOfType怎么用?C# SimpleExpression.GetOperandsOfType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleExpression
的用法示例。
在下文中一共展示了SimpleExpression.GetOperandsOfType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetUpdateCommand
public ICommandBuilder GetUpdateCommand(string tableName, IDictionary<string, object> data, SimpleExpression criteria)
{
var table = _schema.FindTable(tableName);
_commandBuilder.Append(GetUpdateClause(table, data));
if (criteria != null )
{
string whereStatement = null;
if (criteria.GetOperandsOfType<ObjectReference>().Any(o => !o.GetOwner().GetName().Equals(tableName)))
{
if (table.PrimaryKey.Length == 1)
{
whereStatement = CreateWhereInStatement(criteria, table);
}
else if (table.PrimaryKey.Length > 1)
{
whereStatement = CreateWhereExistsStatement(criteria, table);
}
}
else
{
whereStatement = _expressionFormatter.Format(criteria);
}
if (!string.IsNullOrEmpty(whereStatement))
_commandBuilder.Append(" where " + whereStatement);
}
return _commandBuilder;
}
示例2: Upsert
private IDictionary<string, object> Upsert(string tableName, IDictionary<string, object> data, SimpleExpression criteria, bool resultRequired,
IDbConnection connection)
{
var finder = _transaction == null
? new AdoAdapterFinder(_adapter, connection)
: new AdoAdapterFinder(_adapter, _transaction);
var existing = finder.FindOne(tableName, criteria);
if (existing != null)
{
// Don't update columns used as criteria
var keys = criteria.GetOperandsOfType<ObjectReference>().Select(o => o.GetName().Homogenize());
var updateData = data.Where(kvp => keys.All(k => k != kvp.Key.Homogenize())).ToDictionary();
if (updateData.Count == 0)
{
return existing;
}
var commandBuilder = new UpdateHelper(_adapter.GetSchema()).GetUpdateCommand(tableName, updateData, criteria);
if (_transaction == null)
{
_adapter.Execute(commandBuilder, connection);
}
else
{
_adapter.Execute(commandBuilder, _transaction);
}
return resultRequired ? finder.FindOne(tableName, criteria) : null;
}
var inserter = _transaction == null
? new AdoAdapterInserter(_adapter, connection)
: new AdoAdapterInserter(_adapter, _transaction);
return inserter.Insert(tableName, data, resultRequired);
}
示例3: GetUpdateCommand
public ICommandBuilder GetUpdateCommand(string tableName, IDictionary<string, object> data, SimpleExpression criteria)
{
var table = _schema.FindTable(tableName);
var updateClause = GetUpdateClause(table, data);
if (string.IsNullOrWhiteSpace(updateClause)) throw new InvalidOperationException("No columns to update.");
_commandBuilder.Append(updateClause);
if (criteria != null )
{
string whereStatement = null;
if (criteria.GetOperandsOfType<ObjectReference>().Any(o => IsTableChain(tableName, o)))
{
if (table.PrimaryKey.Length == 1)
{
whereStatement = CreateWhereInStatement(criteria, table);
}
else if (table.PrimaryKey.Length > 1)
{
whereStatement = CreateWhereExistsStatement(criteria, table);
}
}
else
{
whereStatement = _expressionFormatter.Format(criteria);
}
if (!string.IsNullOrEmpty(whereStatement))
_commandBuilder.Append(" where " + whereStatement);
}
return _commandBuilder;
}