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


C# IQueryable.Count方法代码示例

本文整理汇总了C#中IQueryable.Count方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.Count方法的具体用法?C# IQueryable.Count怎么用?C# IQueryable.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IQueryable的用法示例。


在下文中一共展示了IQueryable.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateGridDataResponse

        /// <summary>
        /// Generates a GridDataReponse using the GridDataRequest and an IQueryable source,
        /// like a DataSet in Entity Framework.
        /// </summary>
        /// <param name="request">The Tubular's grid request</param>
        /// <param name="dataSource">The IQueryable source</param>
        /// <returns></returns>
        public static GridDataResponse CreateGridDataResponse(this GridDataRequest request, IQueryable dataSource)
        {
            var response = new GridDataResponse
            {
                Counter = request.Counter,
                TotalRecordCount = dataSource.Count(),
                FilteredRecordCount = dataSource.Count()
            };

            var properties = ExtractProperties(dataSource.ElementType);
            var columnMap = MapColumnsToProperties(request.Columns, properties);

            var subset = FilterResponse(request, dataSource, response);

            // Perform Sorting
            var orderingExpression = string.Empty;
            foreach (var column in request.Columns.Where(x => x.SortOrder > 0).OrderBy(x => x.SortOrder))
            {
                orderingExpression += column.Name + " " +
                                      (column.SortDirection == SortDirection.Ascending ? "ASC" : "DESC") + ", ";
            }

            // Apply the sorting expression if supplied
            if (!string.IsNullOrWhiteSpace(orderingExpression))
            {
                subset = subset.OrderBy(orderingExpression.Substring(0, orderingExpression.Length - 2));
            }
            else
            {
                subset = subset.OrderBy(request.Columns.First().Name + " ASC");
            }

            subset = subset.Skip(request.Skip);
            var pageSize = request.Take;

            // Take with value -1 represents entire set
            if (request.Take == -1)
            {
                response.TotalPages = 1;
                response.CurrentPage = 1;
                pageSize = subset.Count();
            }
            else
            {
                subset = subset.Take(request.Take);
                response.TotalPages = (response.FilteredRecordCount + pageSize - 1)/pageSize;

                if (response.TotalPages > 0)
                {
                    response.CurrentPage = 1 +
                                           (int)
                                               ((request.Skip/(float) response.FilteredRecordCount)*response.TotalPages);
                }
            }

            response.Payload = CreateGridPayload(subset, columnMap, pageSize, request.TimezoneOffset);

            return response;
        }
开发者ID:Vic30,项目名称:tubular,代码行数:66,代码来源:Extensions.cs

示例2: RequestsViewModel

        public RequestsViewModel(IQueryable<Request> requests, int pageNo, int pageSize, User user, RequestFilters requestFilter)
        {
            User = user;
            RequestFilter = requestFilter;

            CurrentPage = pageNo;
            PageSize = pageSize;
            TotalResults = requests.Count();

            TotalPages = (int)Math.Ceiling(TotalResults / (float)PageSize);

            if (TotalPages > CurrentPage)
            {
                NextPage = CurrentPage + 1;
            }

            if (CurrentPage > 1)
            {
                PreviousPage = CurrentPage - 1;
            }

            Count = (TotalResults > pageNo * pageSize) ? pageSize : TotalResults - (pageNo - 1) * pageSize;

            if (Count > 0)
            {
                Requests = requests.Skip((pageNo - 1) * pageSize).Take(Count).AsEnumerable().Select(i => new RequestViewModel(user, i));
            }
            else
            {
                Count = 0;

                Requests = new List<RequestViewModel>();
            }
        }
开发者ID:osama-lionheart,项目名称:ServerRequests,代码行数:34,代码来源:RequestsViewModel.cs

示例3: 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

示例4: ByState

 private IQueryable<Order> ByState(IQueryable<Order> orders)
 {
     if (orders == null || orders.Count() <= 0) return null;
     return from order in orders
            orderby order.State
            select order;
 }
开发者ID:solamiku,项目名称:Yiku,代码行数:7,代码来源:SortHelper_Order.cs

示例5: AddDogsInSameCategoryToDogsCollection

        public IQueryable<Dog> AddDogsInSameCategoryToDogsCollection(
            IQueryable<Dog> matchingBreedDogs, int breedId)
        {
            IQueryable<Dog> dogs = null;
              IQueryable<Dog> dogsInSameCategory = null;

              if (matchingBreedDogs.Count() < _configuration.GetSearchResultsMinimumMatchingNumber())
              {
            dogsInSameCategory = GetDogsInSameCategory(breedId);
              }

              if (dogsInSameCategory != null && matchingBreedDogs != null)
              {
            dogs = matchingBreedDogs.Union(dogsInSameCategory);
              }
              else if (dogsInSameCategory == null && matchingBreedDogs != null)
              {
            dogs = matchingBreedDogs;
              }
              else if (dogsInSameCategory != null)
              {
            dogs = dogsInSameCategory;
              }

              return dogs;
        }
开发者ID:jegglestone,项目名称:Animal-Store,代码行数:26,代码来源:DogCategoryService.cs

示例6: PackageListViewModel

        public PackageListViewModel(IQueryable<Package> packages,
            string searchTerm,
            string sortOrder,
            int pageIndex,
            int pageSize,
            UrlHelper url)
        {
            // TODO: Implement actual sorting
            IEnumerable<ListPackageItemViewModel> items;
            using (MiniProfiler.Current.Step("Querying and mapping packages to list"))
            {
                items = packages.SortBy(GetSortExpression(sortOrder))
                                .Skip(pageIndex * pageSize)
                                .Take(pageSize)
                                .ToList()
                                .Select(pv => new ListPackageItemViewModel(pv));
            }
            PageIndex = pageIndex;
            PageSize = pageSize;
            TotalCount = packages.Count();
            SortOrder = sortOrder;
            SearchTerm = searchTerm;
            int pageCount = (TotalCount + PageSize - 1) / PageSize;

            var pager = new PreviousNextPagerViewModel<ListPackageItemViewModel>(
                items,
                PageIndex,
                pageCount,
                page => url.PackageList(page, sortOrder, searchTerm)
            );
            Items = pager.Items;
            FirstResultIndex = 1 + (PageIndex * PageSize);
            LastResultIndex = FirstResultIndex + Items.Count() - 1;
            Pager = pager;
        }
开发者ID:revirth,项目名称:NuGetGallery,代码行数:35,代码来源:PackageListViewModel.cs

示例7: ByPublisher

 private IQueryable<Item> ByPublisher(IQueryable<Item> items)
 {
     if (items == null || items.Count() <= 0) return null;
     return from item in items
            orderby item.PublisherID
            select item;
 }
开发者ID:solamiku,项目名称:Yiku,代码行数:7,代码来源:SortHelper_Item.cs

示例8: ContributionsList

 public IEnumerable<ContributionInfo> ContributionsList(int startRow, int pageSize)
 {
     contributions = FetchContributions();
     if (!_count.HasValue)
         _count = contributions.Count();
     contributions = contributions.Skip(startRow).Take(pageSize);
     return ContributionsList(contributions);
 }
开发者ID:rossspoon,项目名称:bvcms,代码行数:8,代码来源:APIContributionSearchModel.cs

示例9: GetPageList

        public PagerModel GetPageList(PagerDataRequest dataPager, IQueryable queryPaging)
        {
            PagerModel pagerModel = new PagerModel();

            pagerModel.TotalRows = queryPaging.Count();

            #region " Filtering "

            if (dataPager.Filter != null && (dataPager.Filter.Filters != null && dataPager.Filter.Filters.Count > 0))
            {
                //string whereCond = null;
                //var param = new List<object>();
                //var filters = dataPager.Filter.Filters;

                //for (int i = 0; i < filters.Count; i++)
                //{
                //    if (i == 0)
                //    {
                //        whereCond += string.Format(" {0}",)
                //    }
                //    else
                //    {

                //    }
                //}

            }

            #endregion

            #region " Sorting "

            var sort = dataPager.Sort;
            string sortBy = null;

            for (int i = 0; i < sort.Count; i++)
            {
                if (i == sort.Count - 1)
                {
                    sortBy += sortBy + string.Format("{0} {1}", sort[i].Field, sort[i].Dir);
                }
                else
                {
                    sortBy += sortBy + string.Format("{0} {1}, ", sort[i].Field, sort[i].Dir);
                }
            }
            queryPaging = queryPaging.OrderBy(sortBy);

            #endregion

            pagerModel.Data = queryPaging.Skip(dataPager.Skip).Take(dataPager.Take);

            return pagerModel;
        }
开发者ID:sbudihar,项目名称:SIRIUSrepo,代码行数:54,代码来源:PagingService.cs

示例10: ContainsStopEvent

 private bool ContainsStopEvent(IQueryable<events> evnts, int rschId)
 {
     var stopEvrnt = ResearchManager.GetStopEventForRsch(rschId);
     if(stopEvrnt == null) return false;
     if (evnts.Count() == 0) return false;
     foreach (var e in evnts)
     {
         if ((e.dest == stopEvrnt.dest) && (e.module == stopEvrnt.module) && ([email protected] == [email protected]) && (e.who == stopEvrnt.who))
             return true;
     }
     return false;
 }
开发者ID:alexkasp,项目名称:monitor,代码行数:12,代码来源:Form1.cs

示例11: CachePageEvents

        /// <summary>
        /// Caches the page events.
        /// </summary>
        /// <param name="pageEvents">The page events.</param>
        public void CachePageEvents(IQueryable<DMSPollData.Analytics.PageEvent> pageEvents)
        {
            var votesCount = pageEvents.Count();

            if (votesCount > 100)
            {
                int cacheTime = (votesCount <= 1000) ? GetCacheSettings(PollConstants.PollVotesCache100SettingField) : GetCacheSettings(PollConstants.PollVotesCache1000MoreSettingField);
                if (cacheTime > 0)
                    WebUtil.CurrentPage.Cache.Add(PollConstants.PollVotesCachePrefix + PageEventsString, pageEvents, null,
                                              Cache.NoAbsoluteExpiration, new TimeSpan(0, cacheTime, 0),
                                              CacheItemPriority.Low, null);
            }
        }
开发者ID:Warunika,项目名称:SitecorePollModule,代码行数:17,代码来源:PollVotesCache.cs

示例12: FilterPagingSortingSearch

        public IQueryable FilterPagingSortingSearch(DataTablesParam DTParams, IQueryable data, out int totalRecordsDisplay, Tuple<string, Type>[] columns)
        {

            if (!String.IsNullOrEmpty(DTParams.sSearch))
            {
                string searchString = "";
                bool first = true;
                for (int i = 0; i < DTParams.iColumns; i++)
                {
                    if (DTParams.bSearchable[i])
                    {
                        string columnName = columns[i].Item1;

                        if (!first)
                            searchString += " or ";
                        else
                            first = false;

                        if (columns[i].Item2 == typeof(int))
                        {
                            searchString += columnName + ".ToString().StartsWith(\"" + DTParams.sSearch + "\")";
                        }
                        else
                        {
                            searchString += columnName + ".Contains(\"" + DTParams.sSearch + "\")";
                        }
                    }
                }
                data = data.Where(searchString);
            }
            string sortString = "";
            for (int i = 0; i < DTParams.iSortingCols; i++)
            {
                
                int columnNumber = DTParams.iSortCol[i];
                string columnName = columns[columnNumber].Item1;
                string sortDir = DTParams.sSortDir[i];
                if (i != 0)
                    sortString += ", ";
                sortString += columnName + " " + sortDir;
            }

            totalRecordsDisplay = data.Count();

            data = data.OrderBy(sortString);
            data = data.Skip(DTParams.iDisplayStart).Take(DTParams.iDisplayLength);

            return data;
        }
开发者ID:ViktorOstrovskyy,项目名称:mvc.jquery.datatables,代码行数:49,代码来源:DataTablesFilter.cs

示例13: ExportReviewsToXmL

        private XElement ExportReviewsToXmL(IQueryable<Review> reviews)
        {
            var set = new XElement("result-set");
            if (reviews.Count() > 0)
            {
                var orderedReviews = reviews.OrderBy(r => r.Date).ThenBy(r => r.Content);
                foreach (var review in orderedReviews)
                {
                    var xmlReview = new XElement("review");
                    var reviewDate = new XElement("date");
                    reviewDate.Value = review.Date.ToString("d-MMM-yyyy");
                    xmlReview.Add(reviewDate);
                    var reviewConetnt = new XElement("content");
                    reviewConetnt.Value = review.Content;
                    xmlReview.Add(reviewConetnt);
                    var reviewBook = new XElement("book");
                    var bookTitle = new XElement("title");
                    bookTitle.Value = review.Book.Title;
                    reviewBook.Add(bookTitle);
                    if (review.Book.Authors.Count > 0)
                    {
                        var bookAuthors = new XElement("authors");
                        bookAuthors.Value = string.Join(", ", review.Book.Authors.Select(a => a.Name));
                        reviewBook.Add(bookAuthors);
                    }

                    if (review.Book.Isbn != null)
                    {
                        var bookIsbn = new XElement("isbn");
                        bookIsbn.Value = review.Book.Isbn;
                        reviewBook.Add(bookIsbn);
                    }

                    if (review.Book.WebSite != null)
                    {
                        var bookUrl = new XElement("url");
                        bookUrl.Value = review.Book.WebSite;
                        reviewBook.Add(bookUrl);
                    }

                    xmlReview.Add(reviewBook);
                    set.Add(xmlReview);
                }
            }

            return set;
        }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:47,代码来源:QueryParser.cs

示例14: SaveForRapportSuccess

 // Save Rapport
 public string SaveForRapportSuccess(DateTime _date, IQueryable<EcheanceContrat> echeances)
 {
     string _rapport = _date.ToShortDateString();
     _rapport += ";";
     int nb = echeances.Count();
     _rapport += nb;
     _rapport += ";";
     foreach (var item in echeances)
     {
         _rapport += item.Id;
         _rapport += ";";
     }
     if (_rapport.Length > 3500)
     {
         _rapport = _rapport.Substring(0, 3500);
     }
     return _rapport;
 }
开发者ID:paulkornikov,项目名称:Pragonas,代码行数:19,代码来源:EcheanceBatchTraceur.cs

示例15: StartInitialize

        public IQueryable<Product> StartInitialize(IQueryable<Product> entities)
        {
            StartInitializeCommon(entities.Count());
            InitializeProducerFilter(entities);
            InitializeTypesFilter(entities);

            if (ViewModel.GroupsFilter != null && ViewModel.GroupsFilter.GroupList.Any())
            {
                entities = entities.Where(o => ViewModel.GroupsFilter.GroupList.Contains(o.GroupName));
            }

            if (ViewModel.ProducersFilter != null && ViewModel.ProducersFilter.ProducersList.Any())
            {
                entities = entities.Where(o => ViewModel.ProducersFilter.ProducersList.Contains(o.Producer.Name));
            }

            return entities;
        }
开发者ID:vslotylo,项目名称:3e,代码行数:18,代码来源:ListControllerBase.cs


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