本文整理汇总了C#中SimpleExpression类的典型用法代码示例。如果您正苦于以下问题:C# SimpleExpression类的具体用法?C# SimpleExpression怎么用?C# SimpleExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleExpression类属于命名空间,在下文中一共展示了SimpleExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
}
开发者ID:hlach,项目名称:Simple.Data,代码行数:31,代码来源:QueryBuilder.cs
示例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);
}
开发者ID:christianblunden,项目名称:Simple.Data,代码行数:7,代码来源:AdoAdapter.cs
示例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);
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:SimpleQueryTest.cs
示例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;
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:31,代码来源:UpdateHelper.cs
示例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, "!=");
}
开发者ID:fzawada,项目名称:Simple.Data,代码行数:7,代码来源:ExpressionFormatterBase.cs
示例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);
}
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:26,代码来源:AdoAdapterFinder.cs
示例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());
}
开发者ID:remcok,项目名称:Simple.Data,代码行数:7,代码来源:XmlMockAdapter.cs
示例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);
}
开发者ID:Ripper555,项目名称:Simple.Data,代码行数:34,代码来源:AdoAdapterUpserter.cs
示例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;
}
开发者ID:remcok,项目名称:Simple.Data,代码行数:25,代码来源:XmlMockAdapter.cs
示例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;
}
开发者ID:kotsaris,项目名称:Simple.Data,代码行数:29,代码来源:UpdateHelper.cs
示例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);
}
开发者ID:remcok,项目名称:Simple.Data,代码行数:7,代码来源:ExpressionFormatterBase.cs
示例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();
}
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:26,代码来源:ExpressionFormatter.cs
示例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.");
}
开发者ID:rposbo,项目名称:Simple.Data,代码行数:27,代码来源:WhereClauseHandler.cs
示例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();
}
开发者ID:robashton,项目名称:Simple.Data,代码行数:7,代码来源:Joiner.cs
示例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);
}
开发者ID:Jalalhejazi,项目名称:Simple.OData,代码行数:7,代码来源:ODataTableAdapter.cs
示例16: LogicalExpressionToWhereClause
private string LogicalExpressionToWhereClause(SimpleExpression expression)
{
return string.Format("({0} {1} {2})",
Format((SimpleExpression)expression.LeftOperand),
expression.Type.ToString().ToUpperInvariant(),
Format((SimpleExpression)expression.RightOperand));
}
开发者ID:fzawada,项目名称:Simple.Data,代码行数:7,代码来源:ExpressionFormatterBase.cs
示例17: TryFormatAsRange
private string TryFormatAsRange(SimpleExpression expression, IRange range, string op)
{
return (range != null)
?
string.Format("{0} {1} {2}", FormatObject(expression.LeftOperand, expression.RightOperand), op, FormatRange(range, expression.LeftOperand))
:
null;
}
开发者ID:fzawada,项目名称:Simple.Data,代码行数:8,代码来源:ExpressionFormatterBase.cs
示例18: Find
public override IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria)
{
var table = GetTable(tableName);
if (ReferenceEquals(criteria, null)) return table.GetAllRows();
var filter = new ExpressionFormatter().Format(criteria);
return table.Query(filter);
}
开发者ID:yvesgoeleven,项目名称:Simple.Data.Azure,代码行数:8,代码来源:AzureTableAdapter.cs
示例19: NotEqualExpressionToWhereClause
private string NotEqualExpressionToWhereClause(SimpleExpression expression)
{
if (expression.RightOperand == null)
return string.Format("({0} ge '')", FormatObject(expression.LeftOperand));
if (CommonTypes.Contains(expression.RightOperand.GetType())) return FormatAsComparison(expression, "ne");
return FormatAsComparison(expression, "ne");
}
开发者ID:yvesgoeleven,项目名称:Simple.Data.Azure,代码行数:8,代码来源:ExpressionFormatter.cs
示例20: TryFormatAsInList
private string TryFormatAsInList(SimpleExpression expression, IEnumerable list, string op)
{
return (list != null)
?
string.Format("{0} {1} {2}", FormatObject(expression.LeftOperand, expression.RightOperand), op, FormatList(list, expression.LeftOperand))
:
null;
}
开发者ID:fzawada,项目名称:Simple.Data,代码行数:8,代码来源:ExpressionFormatterBase.cs
注:本文中的SimpleExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论