本文整理汇总了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;
}
示例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>();
}
}
示例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 ();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}