本文整理汇总了C#中SimpleQuery.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# SimpleQuery.OrderBy方法的具体用法?C# SimpleQuery.OrderBy怎么用?C# SimpleQuery.OrderBy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleQuery
的用法示例。
在下文中一共展示了SimpleQuery.OrderBy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: OrderByShouldSetOrderAscending
public void OrderByShouldSetOrderAscending()
{
var query = new SimpleQuery(null, "foo");
query = query.OrderBy(new ObjectReference("bar"));
Assert.AreEqual("bar", query.Order.Single().Reference.GetName());
Assert.AreEqual(OrderByDirection.Ascending, query.Order.Single().Direction);
}
示例3: 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);
}
示例4: ThenByShouldModifyOrderAscending
public void ThenByShouldModifyOrderAscending()
{
var query = new SimpleQuery(null, "foo");
query = query.OrderBy(new ObjectReference("bar")).ThenBy(new ObjectReference("quux"));
var actual = query.Order.ToArray();
Assert.AreEqual(2, actual.Length);
Assert.AreEqual("bar", actual[0].Reference.GetName());
Assert.AreEqual(OrderByDirection.Ascending, actual[0].Direction);
Assert.AreEqual("quux", actual[1].Reference.GetName());
Assert.AreEqual(OrderByDirection.Ascending, actual[1].Direction);
}
示例5: GetResult
public virtual async Task<Paged<Entities.Url>> GetResult(Filter.Simple.Data.Filter filter, int? accountId = null)
{
filter.Resource = "Urls";
DataStrategy strategy = Database.Open();
var query = new SimpleQuery(strategy, filter.Resource);
var limit = _limit.Apply(filter);
var skip = _skip.Apply(filter);
dynamic accounts;
query = query.Join(ObjectReference.FromString("Accounts"), JoinType.Inner, out accounts)
.On(accounts.Id == new ObjectReference("AccountId", ObjectReference.FromString("Urls")))
.Select(
new ObjectReference("Id", ObjectReference.FromString("Urls")),
new ObjectReference("Address", ObjectReference.FromString("Urls")),
new ObjectReference("Id", ObjectReference.FromString("Accounts")).As("Account_Id"))
.Skip(_skip.Apply(filter))
.Take(_limit.Apply(filter));
if (accountId.HasValue)
{
var leftOperand = new ObjectReference("AccountId", ObjectReference.FromString("Urls"));
query.Where(new SimpleExpression(leftOperand, accountId, SimpleExpressionType.Equal));
}
if (filter.HasOrdering)
{
query = query.OrderBy(_order.Apply(filter), OrderByDirection.Ascending);
}
var data = await query.ToList<dynamic>();
var entities = AutoMapper.MapDynamic<Entities.Url>(data).ToList();
if (!entities.Any())
{
return null;
}
return new Paged<Entities.Url>
{
Limit = limit,
Skip = skip,
Data = entities
};
}