本文整理汇总了C#中EntityQuery.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# EntityQuery.OrderBy方法的具体用法?C# EntityQuery.OrderBy怎么用?C# EntityQuery.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityQuery
的用法示例。
在下文中一共展示了EntityQuery.OrderBy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OrderingAndPaging
public async Task OrderingAndPaging() {
var entityManager = await TestFns.NewEm(_serviceName);
EntityQuery<Product> query;
IEnumerable<Product> products;
try {
// Products sorted by name
query = new EntityQuery<Product>().Expand("Category").OrderBy(p => p.ProductName);
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// Products sorted by name in descending order
query = new EntityQuery<Product>().Expand("Category").OrderByDescending(p => p.ProductName);
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// Products sorted by price descending, then name ascending
query = new EntityQuery<Product>().Expand("Category").OrderBy(p => p.ProductName).OrderByDescending(p => p.ProductName);
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// look in results for ...
// (27) 'Schoggi Schokolade' at $43.9 in 'Confections',
// (63) 'Vegie-spread' at $43.9 in 'Condiments',...
// Products sorted by related category descending
query = new EntityQuery<Product>().Expand("Category").OrderByDescending(p => p.Category.CategoryName);
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// First 5 of products ordered by product name, then expanded to related category
query = new EntityQuery<Product>().OrderBy(p => p.ProductName).Take(5).Expand("Category");
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// Skip first 10 of products ordered by product name, then expanded to related category
query = new EntityQuery<Product>().OrderBy(p => p.ProductName).Skip(10).Expand("Category");
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// Products paging with skip and take
query = new EntityQuery<Product>().OrderBy(p => p.ProductName).Skip(10).Take(5).Expand("Category");
products = await entityManager.ExecuteQuery(query);
VerifyProductResults(products);
// Inline count of paged products
var productQuery = new EntityQuery<Product>().Where(p => p.ProductName.StartsWith("C"));
var pagedQuery = productQuery.OrderBy(p => p.ProductName).Skip(5).Take(5).InlineCount();
// Execute in parallel and verify products received
var productTask = entityManager.ExecuteQuery(productQuery);
var pagedTask = entityManager.ExecuteQuery(pagedQuery);
await Task.WhenAll(productTask, pagedTask);
var productCount = productTask.Result.Count();
var pageCount = pagedTask.Result.Count();
var pagedQueryResult = pagedTask.Result as QueryResult<Product>;
var inlineCount = pagedQueryResult.InlineCount;
Assert.AreEqual(productCount, inlineCount, "Inline count should return item count excluding skip/take");
Assert.IsTrue(pageCount <= productCount, "Paged query should return subset of total query");
} catch (Exception e) {
var message = TestFns.FormatException(e);
Assert.Fail(message);
}
}