本文整理汇总了C#中SimpleQuery类的典型用法代码示例。如果您正苦于以下问题:C# SimpleQuery类的具体用法?C# SimpleQuery怎么用?C# SimpleQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SimpleQuery类属于命名空间,在下文中一共展示了SimpleQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: RunQuery
public override IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query,
out IEnumerable<SimpleQueryClauseBase>
unhandledClauses)
{
unhandledClauses = query.Clauses.AsEnumerable();
return GetTable(query.TableName);
}
开发者ID:ChrisMH,项目名称:Simple.Data,代码行数:7,代码来源:InMemoryAdapter.cs
示例2: Build
public ICommandBuilder Build(SimpleQuery query)
{
var commandBuilder = new CommandBuilder(GetSelectClause(ObjectName.Parse(query.TableName)), _schema.SchemaProvider);
if (query.Criteria != null)
{
commandBuilder.Append(" WHERE " + new ExpressionFormatter(commandBuilder, _schema).Format(query.Criteria));
}
if (query.Order != null)
{
var orderNames = query.Order.Select(q => q.Reference.GetName() + (q.Direction == OrderByDirection.Descending ? " DESC" : string.Empty));
commandBuilder.Append(" ORDER BY " + string.Join(", ", orderNames));
}
if (query.SkipCount != null || query.TakeCount != null)
{
var queryPager = _adoAdapter.ProviderHelper.GetCustomProvider<IQueryPager>(_adoAdapter.ConnectionProvider);
if (queryPager == null)
{
throw new NotSupportedException("Paging is not supported by the current ADO provider.");
}
var skipTemplate = commandBuilder.AddParameter("skip", DbType.Int32, query.SkipCount ?? 0);
var takeTemplate = commandBuilder.AddParameter("take", DbType.Int32, query.TakeCount ?? int.MaxValue);
commandBuilder.SetText(queryPager.ApplyPaging(commandBuilder.Text, skipTemplate.Name, takeTemplate.Name));
}
return commandBuilder;
}
开发者ID:fzawada,项目名称:Simple.Data,代码行数:30,代码来源:QueryBuilder.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: TakeShouldSetTakeCount
public void TakeShouldSetTakeCount()
{
var query = new SimpleQuery(null, "foo");
query = query.Take(42);
Assert.IsNotNull(query.Clauses.OfType<TakeClause>().FirstOrDefault());
Assert.AreEqual(42, query.Clauses.OfType<TakeClause>().First().Count);
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:SimpleQueryTest.cs
示例5: 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
示例6: RunQuery
public IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query,
out IEnumerable<SimpleQueryClauseBase>
unhandledClauses)
{
IEnumerable<IDictionary<string, object>> result;
if (query.Clauses.OfType<WithCountClause>().Any()) return RunQueryWithCount(query, out unhandledClauses);
ICommandBuilder[] commandBuilders = GetQueryCommandBuilders(query, out unhandledClauses);
IDbConnection connection = _adapter.CreateConnection();
if (_adapter.ProviderSupportsCompoundStatements || commandBuilders.Length == 1)
{
result =
CommandBuilder.CreateCommand(
_adapter.ProviderHelper.GetCustomProvider<IDbParameterFactory>(_adapter.SchemaProvider),
commandBuilders,
connection).ToEnumerable(_adapter.CreateConnection);
}
else
{
result = commandBuilders.SelectMany(cb => cb.GetCommand(connection).ToEnumerable(_adapter.CreateConnection));
}
if (query.Clauses.OfType<WithClause>().Any())
{
result = new EagerLoadingEnumerable(result);
}
return result;
}
开发者ID:tapmantwo,项目名称:Simple.Data,代码行数:30,代码来源:AdoAdapterQueryRunner.cs
示例7: OrderByWithDescendingDirectionShouldSetOrderDescending
public void OrderByWithDescendingDirectionShouldSetOrderDescending()
{
var query = new SimpleQuery(null, "foo");
query = query.OrderBy(new ObjectReference("bar"), OrderByDirection.Descending);
Assert.AreEqual("bar", query.Clauses.OfType<OrderByClause>().Single().Reference.GetName());
Assert.AreEqual(OrderByDirection.Descending, query.Clauses.OfType<OrderByClause>().Single().Direction);
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:SimpleQueryTest.cs
示例8: OrderByBarShouldSetOrderAscending
public void OrderByBarShouldSetOrderAscending()
{
dynamic query = new SimpleQuery(null, "foo");
SimpleQuery actual = query.OrderByBar();
Assert.AreEqual("bar", actual.Clauses.OfType<OrderByClause>().Single().Reference.GetName().ToLowerInvariant());
Assert.AreEqual(OrderByDirection.Ascending, actual.Clauses.OfType<OrderByClause>().Single().Direction);
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:7,代码来源:SimpleQueryTest.cs
示例9: Find
public IEnumerable<IDictionary<string, object>> Find(MongoCollection<BsonDocument> collection, SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
{
var builder = MongoQueryBuilder.BuildFrom(query);
unhandledClauses = builder.UnprocessedClauses;
if (builder.IsTotalCountQuery)
{
long count;
if (builder.Criteria == null)
count = collection.Count();
else
count = collection.Count(_expressionFormatter.Format(builder.Criteria));
//TODO: figure out how to make count a long
builder.SetTotalCount((int)count);
}
if (!builder.SkipCount.HasValue && builder.TakeCount.HasValue && builder.TakeCount.Value == 1)
return new[] { FindOne(collection, builder.Criteria) };
var cursor = CreateCursor(collection, builder.Criteria);
ApplyFields(cursor, builder.Columns);
ApplySorting(cursor, builder.Order);
ApplySkip(cursor, builder.SkipCount);
ApplyTake(cursor, builder.TakeCount);
var aliases = builder.Columns.OfType<ObjectReference>().ToDictionary(x => ExpressionFormatter.GetFullName(x), x => x.GetAlias());
return cursor.Select(x => x.ToSimpleDictionary(aliases));
}
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:32,代码来源:MongoAdapterFinder.cs
示例10: SetQueryContext
private void SetQueryContext(SimpleQuery query)
{
_query = query;
_tableName = ObjectName.Parse(query.TableName.Split('.').Last());
_table = _schema.FindTable(_tableName);
_commandBuilder = new CommandBuilder(GetSelectClause(_tableName), _schema.SchemaProvider);
}
开发者ID:vansha,项目名称:Simple.Data,代码行数:7,代码来源:QueryBuilder.cs
示例11: GetErrors
private static void GetErrors()
{
SimpleQuery p = new SimpleQuery { Site = NetworkSiteEnum.StackOverflow };
IBridgeResponseCollection<ApiException> errors = client.GetErrors(p);
Console.WriteLine(errors.First().ErrorDescription);
}
开发者ID:bevacqua,项目名称:BridgeStack,代码行数:7,代码来源:Program.cs
示例12: RunQuery
public override IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
{
unhandledClauses = Enumerable.Empty<SimpleQueryClauseBase>();
var criteria = query.Clauses.OfType<WhereClause>().Aggregate(SimpleExpression.Empty,
(seed, where) => seed && where.Criteria);
return Find(query.TableName, criteria);
}
开发者ID:remcok,项目名称:Simple.Data,代码行数:7,代码来源:XmlMockAdapter.cs
示例13: OrderByDescendingShouldSetOrderDescending
public void OrderByDescendingShouldSetOrderDescending()
{
var query = new SimpleQuery(null, "foo");
query = query.OrderByDescending(new ObjectReference("bar"));
Assert.AreEqual("bar", query.Order.Single().Reference.GetName());
Assert.AreEqual(OrderByDirection.Descending, query.Order.Single().Direction);
}
开发者ID:darrencauthon,项目名称:Simple.Data,代码行数:7,代码来源:SimpleQueryTest.cs
示例14: Execute
public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)
{
var criteriaExpression = ExpressionHelper.CriteriaDictionaryToExpression(query.TableName,
CreateCriteriaDictionary(binder,
args));
query = query.Where(criteriaExpression).Take(1);
return query.FirstOrDefault();
}
开发者ID:hlach,项目名称:Simple.Data,代码行数:8,代码来源:FindByCommand.cs
示例15: Execute
public object Execute(DataStrategy dataStrategy, SimpleQuery query, InvokeMemberBinder binder, object[] args)
{
var keyNames = dataStrategy.GetAdapter().GetKeyNames(query.TableName);
var dict = keyNames.Select((k, i) => new KeyValuePair<string, object>(k, args[i]));
query = query.Where(ExpressionHelper.CriteriaDictionaryToExpression(query.TableName, dict)).Take(1);
var result = query.FirstOrDefault();
if (result == null) return null;
return binder.Name.Equals("get", StringComparison.OrdinalIgnoreCase) ? result : ((IDictionary<string, object>) result).First().Value;
}
开发者ID:kotsaris,项目名称:Simple.Data,代码行数:9,代码来源:GetCommand.cs
示例16: OrderByBarThenByQuuxShouldSetOrderAscending
public void OrderByBarThenByQuuxShouldSetOrderAscending()
{
dynamic query = new SimpleQuery(null, "foo");
SimpleQuery actual = query.OrderByBar().ThenByQuux();
Assert.AreEqual("bar", actual.Order.First().Reference.GetName().ToLowerInvariant());
Assert.AreEqual("quux", actual.Order.Skip(1).First().Reference.GetName().ToLowerInvariant());
Assert.AreEqual(OrderByDirection.Ascending, actual.Order.First().Direction);
Assert.AreEqual(OrderByDirection.Ascending, actual.Order.Skip(1).First().Direction);
}
开发者ID:darrencauthon,项目名称:Simple.Data,代码行数:9,代码来源:SimpleQueryTest.cs
示例17: Find
public override IEnumerable<IDictionary<string, object>> Find(string tableName, SimpleExpression criteria)
{
var query = new SimpleQuery(this, tableName)
.Where(criteria);
IEnumerable<SimpleQueryClauseBase> unhandledClauses;
return new MongoAdapterFinder(this, _expressionFormatter)
.Find(GetCollection(tableName), query, out unhandledClauses);
}
开发者ID:kppullin,项目名称:Simple.Data.MongoDB,代码行数:9,代码来源:MongoAdapter.cs
示例18: OrderByBarThenQuxxShouldBeAbleToMixOrdering
public void OrderByBarThenQuxxShouldBeAbleToMixOrdering()
{
var query = new SimpleQuery(null, "foo");
query = query.OrderBy(new ObjectReference("bar"), OrderByDirection.Ascending)
.ThenBy(new ObjectReference("quux"), OrderByDirection.Descending);
Assert.AreEqual("bar", query.Clauses.OfType<OrderByClause>().First().Reference.GetName());
Assert.AreEqual("quux", query.Clauses.OfType<OrderByClause>().Skip(1).First().Reference.GetName());
Assert.AreEqual(OrderByDirection.Ascending, query.Clauses.OfType<OrderByClause>().First().Direction);
Assert.AreEqual(OrderByDirection.Descending, query.Clauses.OfType<OrderByClause>().Skip(1).First().Direction);
}
开发者ID:JorgeGamba,项目名称:Simple.Data,代码行数:10,代码来源:SimpleQueryTest.cs
示例19: RunQueryAsObservable
public IObservable<IDictionary<string, object>> RunQueryAsObservable(SimpleQuery query,
out
IEnumerable
<SimpleQueryClauseBase>
unhandledClauses)
{
IDbConnection connection = _adapter.CreateConnection();
return new QueryBuilder(_adapter).Build(query, out unhandledClauses)
.GetCommand(connection, _adapter.AdoOptions)
.ToObservable(connection, _adapter);
}
开发者ID:Ripper555,项目名称:Simple.Data,代码行数:11,代码来源:AdoAdapterQueryRunner.cs
示例20: RunQuery
public override IEnumerable<IDictionary<string, object>> RunQuery(SimpleQuery query, out IEnumerable<SimpleQueryClauseBase> unhandledClauses)
{
unhandledClauses = query.Clauses.Where(c => !(c is WhereClause));
var whereClauses = query.Clauses.OfType<WhereClause>().ToList();
if (whereClauses.Count == 0)
{
return Find(query.TableName, null);
}
return Find(query.TableName,
query.Clauses.OfType<WhereClause>().DefaultIfEmpty().Select(w => w.Criteria).Aggregate((a, b) => a && b));
}
开发者ID:yvesgoeleven,项目名称:Simple.Data.Azure,代码行数:11,代码来源:AzureTableAdapter.cs
注:本文中的SimpleQuery类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论