本文整理汇总了C#中IQueryable.OrderBy方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.OrderBy方法的具体用法?C# IQueryable.OrderBy怎么用?C# IQueryable.OrderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.OrderBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplySort
private IQueryable<JobDTO> ApplySort(IQueryable<JobDTO> source, string sortCriteria)
{
if (string.IsNullOrWhiteSpace(sortCriteria))
{
return source.OrderBy(x => x.ID);
}
string[] sortValues = sortCriteria.Split(' ');
var desceding = false;
if (sortValues.Length > 1)
{
if (sortValues[1].ToUpper() == "DESC")
{
desceding = true;
}
}
if (desceding)
{
return source.OrderBy(sortValues[0] + " descending");
}
else
{
return source.OrderBy(sortValues[0]);
}
}
示例2: GetSorted
private IQueryable<ProductsListViewModel> GetSorted(IQueryable<ProductsListViewModel> allProducts, string sortOrder)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.DateSortParm = String.IsNullOrEmpty(sortOrder) ? "Date" : "";
ViewBag.PriceSortParm = sortOrder == "Price" ? "price_desc" : "Price";
ViewBag.RatingSortParm = sortOrder == "Rating" ? "rating_desc" : "Rating";
switch (sortOrder)
{
case "Rating":
allProducts = allProducts.OrderBy(p => p.Rating);
break;
case "rating_desc":
allProducts = allProducts.OrderByDescending(p => p.Rating);
break;
case "Price":
allProducts = allProducts.OrderBy(p => p.Price);
break;
case "price_desc":
allProducts = allProducts.OrderByDescending(p => p.Price);
break;
case "Date":
allProducts = allProducts.OrderByDescending(p => p.ReleaseDate);
break;
default:
allProducts = allProducts.OrderBy(p => p.ReleaseDate);
break;
}
return allProducts;
}
示例3: OrderProducts
private static IQueryable<Product> OrderProducts(IQueryable<Product> products, string sortOrder)
{
switch (sortOrder)
{
case "desc":
return products.OrderByDescending(p => p.Price).ThenBy(p => p.Name).AsQueryable();
case "asc":
return products.OrderBy(p => p.Price).ThenBy(p => p.Name).AsQueryable();
default: // "abc"
return products.OrderBy(p => p.Name).AsQueryable();
}
}
示例4: ApplySort
public IQueryable<MailingInfo> ApplySort(IQueryable<MailingInfo> query, string sortExpression)
{
switch (sortExpression)
{
case "Name":
return query.OrderBy(mi => mi.Name2);
case "Zip":
return query.OrderBy(mi => mi.Zip);
//break;
default:
break;
}
return query;
}
示例5: ApplySort
public IQueryable<SMSList> ApplySort(IQueryable<SMSList> l)
{
if (Pager.Direction == "asc")
{
switch (Pager.Sort)
{
case "Sent/Scheduled":
l = l.OrderBy(e => e.Created);
break;
case "From":
l = l.OrderBy(e => e.Person.Name);
break;
case "Title":
l = l.OrderBy(e => e.Title);
break;
case "Include":
l = l.OrderBy(e => e.SentSMS);
break;
case "Exclude":
l = l.OrderBy(e => e.SentNone);
break;
}
}
else
{
switch (Pager.Sort)
{
case "Sent/Scheduled":
l = l.OrderByDescending(e => e.Created);
break;
case "From":
l = l.OrderByDescending(e => e.Person.Name);
break;
case "Title":
l = l.OrderByDescending(e => e.Title);
break;
case "Include":
l = l.OrderByDescending(e => e.SentSMS);
break;
case "Exclude":
l = l.OrderByDescending(e => e.SentNone);
break;
default:
l = l.OrderByDescending(e => e.Created);
break;
}
}
return l;
}
示例6: ApplySort
public IQueryable<CmsWeb.Models.MailingController.MailingInfo> ApplySort(IQueryable<CmsWeb.Models.MailingController.MailingInfo> query, string sortExpression)
{
switch (sortExpression)
{
case "Name":
return query.OrderBy(mi => mi.LastName);
case "Zip":
return query.OrderBy(mi => mi.Zip);
//break;
default:
break;
}
return query;
}
示例7: Translate
public IQueryable<MediaContent> Translate(IExpression expression, IQueryable<MediaContent> contentQueryable)
{
this.Visite(expression);
contentQueryable = contentQueryable.Where(this.LinqExpression);
if (this.OrderExprssion != null)
{
if (!this.OrderDesc)
{
contentQueryable = contentQueryable.OrderBy(this.OrderExprssion);
}
else
{
contentQueryable = contentQueryable.OrderByDescending(this.OrderExprssion);
}
}
if (Skip.HasValue)
{
contentQueryable = contentQueryable.Skip(Skip.Value);
}
if (Take.HasValue)
{
contentQueryable = contentQueryable.Take(Take.Value);
}
return contentQueryable;
}
示例8: GetClosestStation
public static Station GetClosestStation(this Station station, IQueryable<Station> stations)
{
if (stations.Count () == 0) {
return Station.NotFoundStation ();
}
return stations.OrderBy (currentStation => SortableApproximateDistance (station, currentStation)).First ();
}
示例9: ApplyFilter
public IQueryable<MarketOrder> ApplyFilter(IQueryable<MarketOrder> query)
{
query = query.Where(pos =>
(filterMagic == null || filterMagic.Value == pos.Magic) &&
(filterSide == null || filterSide.Value == pos.Side) &&
(string.IsNullOrEmpty(filterComment) ||
pos.Comment.Contains(filterComment)) &&
(string.IsNullOrEmpty(filterExpertComment) ||
pos.ExpertComment.Contains(filterExpertComment)) &&
(string.IsNullOrEmpty(filterTicker) ||
pos.Symbol.Contains(filterTicker)) &&
(filterTimeEnterStartsWith == null ||
pos.TimeEnter >= filterTimeEnterStartsWith.Value) &&
(filterTimeEnterEndsWith == null ||
pos.TimeEnter <= filterTimeEnterEndsWith.Value) &&
(filterTimeExitStartsWith == null ||
pos.TimeExit >= filterTimeExitStartsWith) &&
(filterTimeExitEndsWith == null ||
pos.TimeExit <= filterTimeExitEndsWith));
query = (sortAscending ? query.OrderBy(p => sortByTimeEnter ? p.TimeEnter : p.TimeExit)
: query.OrderByDescending(p => sortByTimeEnter ? p.TimeEnter : p.TimeExit))
.Take(takeCount);
return query;
}
示例10: ApplyOrdering
IQueryable<Product> ApplyOrdering(IQueryable<Product> products, string direction)
{
if (products == null)
return null;
return direction == "desc" ? products.OrderByDescending(p => p.Id) : products.OrderBy(p => p.Id);
}
示例11: orderCustomers
private IQueryable<Customer> orderCustomers(IQueryable<Customer> customers, string sortColumn, string sortOrder)
{
if (sortColumn == "CustomerId")
return (sortOrder == "desc") ? customers.OrderByDescending(c => c.CustomerID) : customers.OrderBy(c => c.CustomerID);
if (sortColumn == "Name")
return (sortOrder == "desc") ? customers.OrderByDescending(c=>c.FirstName) : customers.OrderBy(c=>c.FirstName);
if (sortColumn == "Company")
return (sortOrder == "desc")? customers.OrderByDescending(c=>c.CompanyName) : customers.OrderBy(c=>c.CompanyName);
if (sortColumn == "EmailAddress")
return (sortOrder == "desc") ? customers.OrderByDescending(c => c.EmailAddress) : customers.OrderBy(c => c.EmailAddress);
if (sortColumn == "Last Modified")
return (sortOrder == "desc") ? customers.OrderByDescending(c => c.ModifiedDate) : customers.OrderBy(c => c.ModifiedDate);
if (sortColumn == "Telephone")
return (sortOrder == "desc") ? customers.OrderByDescending(c => c.Phone) : customers.OrderBy(c => c.Phone);
return customers;
}
示例12: SelectAllSortTracks
private IQueryable<ChinookModel.Track> SelectAllSortTracks(IQueryable<ChinookModel.Track> query, string sortExpr)
{
if (!String.IsNullOrEmpty(sortExpr))
{
query = query.OrderBy(sortExpr);
}
return query;
}
示例13: ReportBuildQuery
public IQueryable<Country> ReportBuildQuery(IQueryable<Country> query)
{
query = query.Where(q => q.IsActive && !q.IsDeleted);
if (!string.IsNullOrWhiteSpace(Name)) query = query.Where(q => q.Name.Contains(Name));
if (!string.IsNullOrWhiteSpace(ShortCode)) query = query.Where(q => q.ShortCode.Contains(ShortCode));
if (Pager.Size > 0) query = query.OrderBy(x => x.Updated).Skip(Pager.Skip()).Take(Pager.Size);
return query;
}
示例14: GetListUsers
// GET: GetListUserList
public PartialViewResult GetListUsers(string SortOrder, string CurrentFilter, string SearchString, int? Page = 1)
{
int pageSize = 10;
ViewBag.CurrentSort = SortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(SortOrder) ? "Name_desc" : "";
ViewBag.UsernameSortParm = SortOrder == "Username" ? "Username_desc" : "Username";
ViewBag.EmailSortParm = SortOrder == "Email" ? "Email_desc" : "Email";
if (SearchString != null)
{
Page = 1;
}
else
{
SearchString = CurrentFilter;
}
ViewBag.CurrentFilter = SearchString;
UserList = UOW.UserRepository.Get();
if (!String.IsNullOrEmpty(SearchString))
{
UserList = UserList.Where(s => s.Name.Contains(SearchString)
|| s.Username.Contains(SearchString)
|| s.EmailAdress.Contains(SearchString));
}
ViewBag.Count = UserList.Count();
switch (SortOrder)
{
case "Name_desc":
UserList = UserList.OrderByDescending(s => s.Name);
break;
case "Username":
UserList = UserList.OrderBy(s => s.Username);
break;
case "Username_desc":
UserList = UserList.OrderByDescending(s => s.Username);
break;
case "Email":
UserList = UserList.OrderBy(s => s.EmailAdress);
break;
case "Email_desc":
UserList = UserList.OrderByDescending(s => s.EmailAdress);
break;
default:
UserList = UserList.OrderBy(s => s.Name);
break;
}
int pageNumber = (Page ?? 1);
return PartialView("GetListUsers",UserList.ToList().ToPagedList(pageNumber, pageSize));
}
示例15: Sort
protected IQueryable<ProductViewModel> Sort(IQueryable<ProductViewModel> products, string sortBy, string sortOrder)
{
if (sortBy == SortByDefault)
{
if (sortOrder == SortOrderDefault)
return products.OrderByDescending(p => p.Likes.Count);
else
return products.OrderBy(p => p.Likes.Count);
}
if (sortBy == "Price")
{
if (sortOrder == SortOrderDefault)
return products.OrderByDescending(p => p.Price);
}
return products.OrderBy(p => p.Price);
}