本文整理汇总了C#中IQueryable.Take方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.Take方法的具体用法?C# IQueryable.Take怎么用?C# IQueryable.Take使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.Take方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: dumpQuery
private static void dumpQuery(IQueryable<Customer> qry, int topN)
{
foreach (Customer c in qry.Take(topN))
{
Console.WriteLine(String.Format("{0} {1} {2}",c.Title, c.FirstName, c.LastName));
}
}
示例2: 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;
}
示例3: PagedTaskSource
public PagedTaskSource(IQueryable<TaskRow> source, string partition, string rowKey, int pageSize)
{
this.PageSize = pageSize;
var query = source.Take(this.PageSize) as DataServiceQuery<TaskRow>;
if (query != null)
{
if (partition != null && rowKey != null)
{
query = query
.AddQueryOption("NextPartitionKey", partition)
.AddQueryOption("NextRowKey", rowKey);
}
// set the Tasks
var res = query.Execute();
this.Tasks = res.ToModel();
// get the continuation markers
string nextPartition;
string nextRow;
var headers = ((QueryOperationResponse)res).Headers;
headers.TryGetValue("x-ms-continuation-NextPartitionKey", out nextPartition);
headers.TryGetValue("x-ms-continuation-NextRowKey", out nextRow);
// and return them to the client
this.NextPartition = nextPartition;
this.NextRow = nextRow;
}
}
示例4: PlayerDashBoardViewModel
public PlayerDashBoardViewModel(IEnumerable<League> leagues, Season currentSeason, IEnumerable<PlayerPredictionSummary> predictions, IEnumerable<PlayerPredictionSummary> LastWeekPredictions, Player playerProfile, Week LastWeek, Boolean IsViewingMyOwnPage, IQueryable<Notification> repnotifications)
{
LeagueSelections = leagues.ToDictionary((x => x.Name), x => x.Id.ToString());
CurrentSeasonText = string.Format("{0} - {1} to {2}", currentSeason.League.Name, currentSeason.SeasonStarts.ToLongDateString(), currentSeason.SeasonEnd.ToLongDateString());
ThisWeek = currentSeason.GetCurrentWeekSeason();
IsMyPage = IsViewingMyOwnPage;
if (predictions != null)
{
PredictionsWithOutComes = predictions.Where(x => x.HasOutcome).OrderBy(y=>y.MatchDate);
PredictionUpComingMatches = predictions.Where(x => !x.HasOutcome).OrderBy(y => y.MatchDate);
ThisWeeksMotWId = ThisWeek != null && ThisWeek.MatchOfTheWeek != null ? ThisWeek.MatchOfTheWeek.Id : 0;
}
if (LastWeekPredictions != null)
{
PredictionsOfPreviousWeek = LastWeekPredictions.OrderBy(y => y.MatchDate);
LastWeeksMotWId = LastWeek != null && LastWeek.MatchOfTheWeek != null ? LastWeek.MatchOfTheWeek.Id : 0;
}
//Build Players Table
Points = currentSeason.Weeks.WeeksSoFar().Select(w => currentSeason.GetTotalPointsForAPlayersWeek(playerProfile, w)).ToList();
WeekNames = currentSeason.Weeks.WeeksSoFar().Select(x => x.WeekStarts.Day.ordinalNum() + " " + x.WeekStarts.ToString("MMM")).ToArray();
//set up notifications
notifications = repnotifications.Take(3);
AllPredictionsConfirmed = ThisWeek != null ? playerProfile.HasCompletedPredictions(ThisWeek) : true;
}
示例5: Filter
public IQueryable<Report> Filter(IQueryable<Report> reports)
{
if (this.fromDate != null) {
reports = reports.Where(r => r.Date >= this.fromDate);
}
if (this.toDate != null) {
reports = reports.Where(r => r.Date <= this.toDate);
}
if (this.ProjectId !=null) {
reports = reports.Where(r => r.ProjectId == this.ProjectId);
}
if (this.UserId != null) {
reports = reports.Where(r => r.UserId == this.UserId);
}
if (this.Limit != null) {
reports = reports.Take(Limit.Value);
}
return reports.OrderByDescending(r => r.Id);
}
示例6: Apply
public IQueryable Apply(IQueryable data)
{
if (_orderBy != null) data = _orderBy(data);
if (_offset != null) data = data.Skip(_offset.Value);
if (_limit != null) data = data.Take(_limit.Value);
if(!_selectStar) data = SelectDynamic(data, _columns);
return data;
}
示例7: Execute
protected virtual object Execute(IQueryable<TextContent> queryable, IEnumerable<OrderExpression> orders, CallType callType, int? skip, int? take)
{
#region Order query
IOrderedQueryable<TextContent> ordered = null;
foreach (var orderItem in orders)
{
if (!orderItem.Descending)
{
if (ordered == null)
{
ordered = queryable.OrderBy(orderItem.OrderExprssion);
}
else
{
ordered = ordered.ThenBy(orderItem.OrderExprssion);
}
}
else
{
if (ordered == null)
{
ordered = queryable.OrderByDescending(orderItem.OrderExprssion);
}
else
{
ordered = ordered.ThenByDescending(orderItem.OrderExprssion);
}
}
}
if (ordered != null)
{
queryable = ordered;
}
#endregion
if (skip.HasValue)
{
queryable = queryable.Skip(skip.Value);
}
if (take.HasValue)
{
queryable = queryable.Take(take.Value);
}
switch (callType)
{
case Kooboo.CMS.Content.Query.Expressions.CallType.Count:
return queryable.Count();
case Kooboo.CMS.Content.Query.Expressions.CallType.First:
return queryable.First();
case Kooboo.CMS.Content.Query.Expressions.CallType.Last:
return queryable.Last();
case Kooboo.CMS.Content.Query.Expressions.CallType.LastOrDefault:
return queryable.LastOrDefault();
case Kooboo.CMS.Content.Query.Expressions.CallType.FirstOrDefault:
return queryable.FirstOrDefault();
case Kooboo.CMS.Content.Query.Expressions.CallType.Unspecified:
default:
return queryable.ToArray();
}
}
示例8: SUP_Load
void SUP_Load(object sender, EventArgs e)
{
//check if user is authenticated
authenticated = HttpContext.Current.User.Identity.IsAuthenticated;
btnShowReview.Visible = authenticated;
//get the current user's username
username = SecurityManager.GetCurrentUserName();
userid = SecurityManager.GetCurrentUserId();
//determine the url name to be compared for product declaration
url = System.IO.Path.GetFileName(HttpContext.Current.Request.Url.AbsolutePath);
//execute loading logic if the current page url is of a valid product. This also sets the product object
isValid = isValidProduct(url);
if (isValid)
{
//get the customer based off the current user ID
if (userid != null && userid != Guid.Empty)
{
currentCustomer = GetCustomerByUser(userid);
}
//start verifying whether the current user (customer) has purchased this product before.
if (currentCustomer != null)
{
verifiedPurchase = wasPurchased(product.Id, currentCustomer.Id);
}
//get the reviews based on the product id
source = GetReviewsById(product.Id);
//count the reviews for this product
int count = source.Count();
//determine of the current user has reviewed this product before
userReviewed = alreadyReviewed(source, username);
//set the labels with the appropriate values
setLabels(username, userReviewed, count);
//get the average rating of the product and set it to the RadRating control
decimal avg = totalRating(source);
ratingOverview.Value = avg;
//get the current user's avatar and bind the RadListView with the comments for this product
imgCurrentAvatar.DataValue = GetImage(username);
//set the data source
listReviews.DataSource = source.Take(showCount);
//we'll bind it here if it's not a postback. Postback bindings should be handled by their controls.
if (!IsPostBack)
{
hdCount.Value = showCount.ToString();
listReviews.DataBind();
}
//hide or show the load button
btnLoadMore.Visible = (showCount < count);
}
//if the product is not visible then we hide the controls and stop here
else
{
SUP.Visible = false;
}
}
示例9: Apply
public IQueryable Apply(IQueryable data)
{
if (!string.IsNullOrWhiteSpace(Select)
|| !string.IsNullOrWhiteSpace(Label)
|| !string.IsNullOrWhiteSpace(Options)
|| !string.IsNullOrWhiteSpace(Format)
|| !string.IsNullOrWhiteSpace(Pivot)
|| !string.IsNullOrWhiteSpace(GroupBy))
{
throw new NotSupportedException("One or more clauses in this query are not supported.");
}
if (!string.IsNullOrWhiteSpace(Where))
{
if (Where.Contains(" and ") || Where.Contains(" or ") || Where.Contains(" not ")) throw new NotSupportedException("Multiple criteria in the where clause are not supported.");
var match = _whereRegex.Match(Where);
if (!match.Success)
{
throw new FormatException("The 'Where' clause is in an invalid format.");
}
var left = match.Groups["operand1"].Value;
var right = match.Groups["operand2"].Value;
var op = match.Groups["operator"].Value;
//HACK: assuming left is property and right is constant
var propertyName = left;
var constantValue = right.Trim().Trim('\'', '"');
switch (op)
{
case "contains":
data = data.WherePropertyContains(propertyName, constantValue, StringComparison.OrdinalIgnoreCase);
break;
case "like":
case "starts with":
case "ends with":
case "<=":
case "<":
case ">":
case ">=":
case "=":
case "!=":
case "<>":
throw new NotSupportedException(string.Format("The operator '{0}' is not yet supported.", op));
}
}
if (!string.IsNullOrWhiteSpace(OrderBy))
{
if (OrderBy.Contains(",")) throw new NotSupportedException("Multiple column ordering not supported.");
var desc = OrderBy.EndsWith("desc");
var columnName = OrderBy.Replace(" asc", string.Empty).Replace(" desc", string.Empty).Trim(' ', '`');
if (desc)
{
data = data.OrderByDescending(columnName);
}
else
{
data = data.OrderBy(columnName);
}
}
//Offset and Limit have to be in this order...
if (Offset != null)
{
data = data.Skip(Offset.Value);
}
if (Limit != null)
{
data = data.Take(Limit.Value);
}
return data;
}
示例10: GetStaffQueryPaged
/// <summary>
/// Gets the staff query paged.
/// </summary>
/// <param name="startIndex">The start index.</param>
/// <param name="pageSize">Size of the page.</param>
/// <param name="query">The query.</param>
/// <returns></returns>
private IQueryable<Staff> GetStaffQueryPaged(int startIndex, int pageSize, IQueryable<Staff> query)
{
query = query.Skip(startIndex);
query = query.Take(pageSize);
return query;
}
示例11: AddCurrentUser
/// <summary>
/// @author: Guillaume Jacques
/// method checking for the current user and add its character if this character is
/// not in the leaderboard already.
/// </summary>
/// <param name="characters">list of the characters in the selected set according to
/// the sorting method sleected</param>
/// <returns>list of characters including the current user if not already in the initial
/// set of characters</returns>
private List<Character> AddCurrentUser(IQueryable<Character> characters)
{
// check if the current user is in the leaderboard if so get the position
ViewBag.user_Position = getUserIndex(characters);
ViewBag.user = (getCurrentCharacter()).id;
List<Character> cl = characters.Take(10).ToList();
// if not in leaderboard add to the list
if (!isInLeaderboard(cl))
{
cl.Add(getCurrentCharacter());
if (ViewBag.user_Position == 10)
{
ViewBag.user_Position = 11;
}
return cl;
}
return cl;
}
示例12: SelectPackageRange
IQueryable<IPackage> SelectPackageRange(IQueryable<IPackage> packages)
{
if (skip.HasValue) {
packages = packages.Skip(skip.Value);
}
if (first.HasValue) {
packages = packages.Take(first.Value);
}
return packages;
}
示例13: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
authenticated = HttpContext.Current.User.Identity.IsAuthenticated;
if (authenticated)
{
username = SecurityManager.GetCurrentUserName();
source = GetReviewsByUser(username);
listReviews.DataSource = source.Take(initialLoad);
listReviews.DataBind();
if (!IsPostBack)
{
hdLoadCount.Value = initialLoad.ToString();
}
if (int.Parse(hdLoadCount.Value) >= source.Count())
{
btnLoadMoreReviews.Visible = false;
}
}
else
{
SUP.Visible = false;
}
}
示例14: WaitingToBeQuotedOrdersByTrader_PreprocessQuery
partial void WaitingToBeQuotedOrdersByTrader_PreprocessQuery(string TraderAccount, ref IQueryable<Order> query)
{
query = query.Take(5);
}
示例15: FilterMaps
static ZkDataContext FilterMaps(string search,
bool? supported,
bool? featured,
int? offset,
bool? assymetrical,
int? sea,
int? hills,
int? size,
bool? elongated,
bool? needsTagging,
bool? isTeams,
bool? is1v1,
bool? ffa,
bool? chicken,
int? isDownloadable,
int? special,
out IQueryable<Resource> ret) {
var db = new ZkDataContext();
if (featured == null) featured = true;
ret = db.Resources.Where(x => x.TypeID == ResourceType.Map);
if (!string.IsNullOrEmpty(search)) {
foreach (var word in search.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) {
var w = word;
ret = ret.Where(x => x.InternalName.Contains(w) || x.AuthorName.Contains(w));
}
}
if (needsTagging == true) {
ret =
ret.Where(
x =>
x.MapIsFfa == null || x.MapIsAssymetrical == null || x.MapIsSpecial == null || x.AuthorName == null || x.MapHills == null ||
x.MapWaterLevel == null);
}
if (supported == true) ret = ret.Where(x => x.MapIsSupported == true);
if (featured == true) ret = ret.Where(x => x.FeaturedOrder > 0);
if (isDownloadable == 1) ret = ret.Where(x => x.ResourceContentFiles.Any(y => y.LinkCount > 0));
else if (isDownloadable == 0) ret = ret.Where(x => x.ResourceContentFiles.All(y => y.LinkCount <= 0));
if (special != -1) ret = ret.Where(x => x.MapIsSpecial == (special == 1));
if (sea.HasValue) ret = ret.Where(x => x.MapWaterLevel == sea);
if (hills.HasValue) ret = ret.Where(x => x.MapHills == hills);
if (assymetrical.HasValue) ret = ret.Where(x => x.MapIsAssymetrical == assymetrical);
if (elongated == true) ret = ret.Where(x => x.MapSizeRatio <= 0.5 || x.MapSizeRatio >= 2);
else if (elongated == false) ret = ret.Where(x => x.MapSizeRatio > 0.5 && x.MapSizeRatio < 2);
// Diagonal of a map used to determine size; 16 and below are considered small, bigger than 24 is large
if (size == 1) ret = ret.Where(x => (x.MapHeight*x.MapHeight + x.MapWidth*x.MapWidth) <= 16*16);
else if (size == 2) {
ret =
ret.Where(
x =>
(x.MapHeight*x.MapHeight + x.MapWidth*x.MapWidth) > 16*16 &&
(x.MapHeight*x.MapHeight + x.MapWidth*x.MapWidth) <= 24*24);
}
else if (size == 3) ret = ret.Where(x =>(x.MapHeight*x.MapHeight + x.MapWidth*x.MapWidth) > 24*24);
if (isTeams.HasValue) ret = ret.Where(x => x.MapIsTeams == isTeams);
if (is1v1.HasValue) ret = ret.Where(x => x.MapIs1v1 == is1v1);
if (chicken.HasValue) ret = ret.Where(x => x.MapIsChickens == chicken);
if (ffa.HasValue) ret = ret.Where(x => x.MapIsFfa == ffa);
//if (featured == true) ret = ret.OrderByDescending(x => -x.FeaturedOrder).ThenByDescending(x => x.ResourceID);
//else ret = ret.OrderByDescending(x => x.ResourceID);
ret = ret.OrderByDescending(x => x.ResourceID);
if (offset != null) ret = ret.Skip(offset.Value);
ret = ret.Take(Global.AjaxScrollCount);
return db;
}