本文整理汇总了C#中SimpleExpression类的典型用法代码示例。如果您正苦于以下问题:C# SimpleExpression类的具体用法?C# SimpleExpression怎么用?C# SimpleExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SimpleExpression类属于命名空间,在下文中一共展示了SimpleExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetQueryContext
private void SetQueryContext(SimpleQuery query)
{
_query = query;
_tableName = _schema.BuildObjectName(query.TableName);
_table = _schema.FindTable(_tableName);
var selectClause = _query.Clauses.OfType<SelectClause>().SingleOrDefault();
if (selectClause != null)
{
if (selectClause.Columns.OfType<AllColumnsSpecialReference>().Any())
{
_columns = ExpandAllColumnsReferences(selectClause.Columns).ToArray();
}
else
{
_columns = selectClause.Columns.ToArray();
}
}
else
{
_columns = _table.Columns.Select(c => ObjectReference.FromStrings(_table.Schema, _table.ActualName, c.ActualName)).ToArray();
}
HandleWithClauses();
_whereCriteria = _query.Clauses.OfType<WhereClause>().Aggregate(SimpleExpression.Empty,
(seed, where) => seed && where.Criteria);
_havingCriteria = _query.Clauses.OfType<HavingClause>().Aggregate(SimpleExpression.Empty,
(seed, having) => seed && having.Criteria);
_commandBuilder.SetText(GetSelectClause(_tableName));
}
示例2: Find
public IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria)
{
if (criteria == null) return FindAll(tableName);
var commandBuilder = new FindHelper(_schema).GetFindByCommand(tableName, criteria);
return ExecuteQuery(commandBuilder);
}
示例3: WhereShouldSetCriteria
public void WhereShouldSetCriteria()
{
var query = new SimpleQuery(null, "foo");
var criteria = new SimpleExpression(1, 1, SimpleExpressionType.Equal);
query = query.Where(criteria);
Assert.AreSame(criteria, query.Clauses.OfType<WhereClause>().Single().Criteria);
}
示例4: 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;
}
示例5: NotEqualExpressionToWhereClause
private string NotEqualExpressionToWhereClause(SimpleExpression expression)
{
if (expression.RightOperand == null) return string.Format("{0} IS NOT NULL", expression.LeftOperand);
if (CommonTypes.Contains(expression.RightOperand.GetType())) return FormatAsComparison(expression, "!=");
return FormatAsComparison(expression, "!=");
}
示例6: CreateFindOneDelegate
public Func<object[],IDictionary<string,object>> CreateFindOneDelegate(string tableName, SimpleExpression criteria)
{
if (criteria == null)
{
return _ => FindAll(_adapter.GetSchema().BuildObjectName(tableName)).FirstOrDefault();
}
var commandBuilder = new FindHelper(_adapter.GetSchema())
.GetFindByCommand(_adapter.GetSchema().BuildObjectName(tableName), criteria);
var command = commandBuilder.GetCommand(_adapter.CreateConnection(), _adapter.AdoOptions);
command = _adapter.CommandOptimizer.OptimizeFindOne(command);
var commandTemplate =
commandBuilder.GetCommandTemplate(
_adapter.GetSchema().FindTable(_adapter.GetSchema().BuildObjectName(tableName)));
var cloneable = command as ICloneable;
if (cloneable != null)
{
return args => ExecuteSingletonQuery((IDbCommand)cloneable.Clone(), args, commandTemplate.Index);
}
else
{
return args => ExecuteSingletonQuery(commandTemplate, args);
}
}
示例7: Find
public override IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria)
{
if (criteria == null) return FindAll(tableName);
return GetTableElement(tableName).Elements()
.Where(XmlPredicateBuilder.GetPredicate(criteria))
.Select(e => e.AttributesToDictionary());
}
示例8: 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);
}
示例9: Update
public override int Update(string tableName, IDictionary<string, object> data, SimpleExpression criteria)
{
int updated = 0;
var elementsToUpdate = GetTableElement(tableName).Elements()
.Where(XmlPredicateBuilder.GetPredicate(criteria));
foreach (var element in elementsToUpdate)
{
foreach (var kvp in data)
{
var attribute = element.TryGetAttribute(kvp.Key);
if (attribute != null)
{
attribute.Value = kvp.Value.ToString();
}
else
{
element.SetAttributeValue(kvp.Key, kvp.Value);
}
}
updated++;
}
return updated;
}
示例10: 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;
}
示例11: NotEqualExpressionToWhereClause
private string NotEqualExpressionToWhereClause(SimpleExpression expression)
{
if (expression.RightOperand == null) return string.Format("{0} {1}", FormatObject(expression.LeftOperand, null), Operators.IsNotNull);
if (CommonTypes.Contains(expression.RightOperand.GetType())) return FormatAsComparison(expression, "!=");
return FormatAsComparison(expression, Operators.NotEqual);
}
示例12: Format
public QueryComplete Format(SimpleExpression expression)
{
switch (expression.Type)
{
case SimpleExpressionType.And:
return LogicalExpression(expression, (l, r) => Query.And(l, r));
case SimpleExpressionType.Equal:
return EqualExpression(expression);
case SimpleExpressionType.GreaterThan:
return BinaryExpression(expression, Query.GT);
case SimpleExpressionType.GreaterThanOrEqual:
return BinaryExpression(expression, Query.GTE);
case SimpleExpressionType.LessThan:
return BinaryExpression(expression, Query.LT);
case SimpleExpressionType.LessThanOrEqual:
return BinaryExpression(expression, Query.LTE);
case SimpleExpressionType.Function:
return FunctionExpression(expression);
case SimpleExpressionType.NotEqual:
return NotEqualExpression(expression);
case SimpleExpressionType.Or:
return LogicalExpression(expression, (l, r) => Query.Or(l, r));
}
throw new NotSupportedException();
}
示例13: FunctionExpressionToWhereClause
private Func<IDictionary<string, object>, bool> FunctionExpressionToWhereClause(SimpleExpression arg)
{
var function = arg.RightOperand as SimpleFunction;
if (ReferenceEquals(function, null)) throw new InvalidOperationException("Expression type of function but no function supplied.");
if (function.Name.Equals("like", StringComparison.OrdinalIgnoreCase) ||
function.Name.Equals("notlike", StringComparison.OrdinalIgnoreCase))
{
var pattern = function.Args[0].ToString();
if (pattern.Contains("%") || pattern.Contains("_")) // SQL Server LIKE
{
pattern = pattern.Replace("%", ".*").Replace('_', '.');
}
var regex = new Regex("^" + pattern + "$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
if (function.Name.Equals("like", StringComparison.OrdinalIgnoreCase))
{
return d => Resolve(d, arg.LeftOperand).Count > 0 && Resolve(d, arg.LeftOperand).OfType<string>().Any(regex.IsMatch);
}
if (function.Name.Equals("notlike", StringComparison.OrdinalIgnoreCase))
{
return d => Resolve(d, arg.LeftOperand).Count > 0 && Resolve(d, arg.LeftOperand).OfType<string>().All(input => !regex.IsMatch(input));
}
}
throw new NotSupportedException("Expression Function not supported.");
}
示例14: GetTableNames
private static IEnumerable<Tuple<ObjectName,ObjectName>> GetTableNames(SimpleExpression expression, string schema)
{
return GetReferencesFromExpression(expression)
.SelectMany(r => DynamicReferenceToTuplePairs(r, schema))
.Select((table1, table2) => Tuple.Create(new ObjectName(schema, table1), new ObjectName(schema, table2)))
.Distinct();
}
示例15: FindByExpression
private IEnumerable<IDictionary<string, object>> FindByExpression(string tableName, SimpleExpression criteria)
{
var builder = new CommandBuilder(GetSchema().FindTable, GetKeyNames);
var cmd = builder.BuildCommand(tableName, criteria);
return FindEntries(cmd.CommandText);
}