当前位置: 首页>>代码示例>>C#>>正文


C# IQueryable.OrderBy方法代码示例

本文整理汇总了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]);
            }
        }
开发者ID:jupaol,项目名称:LearningProjects,代码行数:27,代码来源:ObjectDataSourceProvider.cs

示例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;
        }
开发者ID:clangelov,项目名称:ASP.NET-MVC-Course-Project,代码行数:31,代码来源:ProductsController.cs

示例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();
     }
 }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:12,代码来源:CatalogueModel.cs

示例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;
 }
开发者ID:clearfunction,项目名称:bvcms,代码行数:14,代码来源:MailingController.cs

示例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;
        }
开发者ID:stevesloka,项目名称:bvcms,代码行数:50,代码来源:SMSModel.cs

示例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;
 }
开发者ID:hkouns,项目名称:bvcms,代码行数:14,代码来源:MailingController.cs

示例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;
            }
开发者ID:Godoy,项目名称:CMS,代码行数:29,代码来源:MediaContentProvider.cs

示例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 ();
		}
开发者ID:305088020,项目名称:ChART,代码行数:7,代码来源:StationExtensions.cs

示例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;
        }
开发者ID:johnmensen,项目名称:TradeSharp,代码行数:25,代码来源:OrderFilterAndSortOrder.cs

示例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);
 }
开发者ID:fathurxzz,项目名称:aleqx,代码行数:7,代码来源:SiteModel.cs

示例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;
 }
开发者ID:reharik,项目名称:MvcJqGrid,代码行数:16,代码来源:Repository.cs

示例12: SelectAllSortTracks

		private IQueryable<ChinookModel.Track> SelectAllSortTracks(IQueryable<ChinookModel.Track> query, string sortExpr)
		{
			if (!String.IsNullOrEmpty(sortExpr))
			{
				query = query.OrderBy(sortExpr);
			}
			return query;
		}
开发者ID:tforsberg,项目名称:z,代码行数:8,代码来源:ChinookMedia.cs

示例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;
        }
开发者ID:biggash730,项目名称:SemanticUI_Knockout_ASPMVC_Starter,代码行数:9,代码来源:Filters.cs

示例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));
        }
开发者ID:marquesdasilva,项目名称:UserManager_v02,代码行数:58,代码来源:WBUserListController.cs

示例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);
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:18,代码来源:BaseController.cs


注:本文中的IQueryable.OrderBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。