本文整理汇总了C#中IQueryable.Select方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.Select方法的具体用法?C# IQueryable.Select怎么用?C# IQueryable.Select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.Select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getStatsFor
private IQueryable<Stats> getStatsFor(IQueryable<IGrouping<string, Order>> query)
{
return query.Select(y => new Stats {
Key = y.Key,
Count = y.Count()
}).Select(e => e);
}
示例2: FindPageOfMovies
public static IEnumerable<FullViewModel> FindPageOfMovies(IQueryable<FullViewModel> res,
int page,
int movie_count,
MovieDbContext db,
bool verbose=false)
{
var page_start = Tools.WriteTimeStamp(writeTime:false);
if (verbose) { Tools.TraceLine(" Retrieving paginated results"); }
int movies_to_skip = movie_count * (page - 1);
var ids = res.Select(nit => nit.Movie.movie_ID).ToArray();
if (verbose) { Tools.TraceLine(" sorting movie ids"); }
//take all the movie_id up to and including the ones you'll show
// on page, then only take the last set of movie_ids you'll show
var sortedIds =
ids.OrderBy(movie_id => movie_id)
.Skip(movies_to_skip)
.Take(movie_count)
.ToArray();
if (verbose) { Tools.TraceLine(" grabbing matched movies"); }
var nit_qry =
Tools.GetFullDbQuery(db)
.Where(
viewModel =>
sortedIds.Any(
movie_id => movie_id == viewModel.Movie.movie_ID));
IEnumerable<FullViewModel> nit_list = nit_qry.ToList();
if (verbose) { Tools.TraceLine(" done matching movies, returning"); }
var page_end = Tools.WriteTimeStamp(writeTime:false);
if (verbose) { Tools.TraceLine(" Taking first page of movies {0}", (page_end - page_start).ToString()); }
return nit_list;
}
示例3: ArticleModelEditViewManagement
public ArticleModelEditViewManagement(IQueryable<Data.User> users)
{
AvailablePostprocessors = ProcessorHelper.GetPostprocessors()
.ToDictionary(ppType => ppType.AssemblyQualifiedName, ppType => ppType.GetProcessorDisplayName());
AvailableAuthors = users
.Select(u => new SelectListItem { Value = u.UserId.ToString(), Text = u.DisplayName, });
}
示例4: ConnectTagsToArticle
public static void ConnectTagsToArticle(this DbSet<ArticleTag> source, Article article, IQueryable<Tag> tags)
{
var articleTags = tags.Select(t => new ArticleTag
{
ArticleId = article.ArticleId,
TagId = t.TagId,
}).ToList();
source.AddRange(articleTags);
}
示例5: GetSearchSuggestionSeriesQuery
public IQueryable<SerieItemModel> GetSearchSuggestionSeriesQuery(IQueryable<Serie> query)
{
IQueryable<SerieItemModel> series = query.Select(br => new SerieItemModel
{
Id = br.SerieId,
Name = br.Name,
Authors = br.BookInSeries.SelectMany(bi=>bi.Book.Authors).Select(a => new AuthorItemModel() { Id = a.AuthorId, Name = a.Name }),
Rating = new RatingModel { Value = (double?)br.Ratings.Average(r => r.Value) ?? 0 },
HasImage = false
});
return series;
}
示例6: GetSearchSuggestionBooksQuery
public IQueryable<BookItemModel> GetSearchSuggestionBooksQuery(IQueryable<Book> query)
{
IQueryable<BookItemModel> books = query.Select(br => new BookItemModel
{
Id = br.BookId,
Name = br.Name,
Authors = br.Authors.Select(a => new AuthorItemModel() { Id = a.AuthorId, Name = a.Name }),
Rating = new RatingModel { Value = (double?)br.Ratings.Average(r => r.Value) ?? 0 },
HasImage = br.Cover != null
});
return books;
}
示例7: CreateProductListViewModel
internal PaginatedList<ProductListViewModel> CreateProductListViewModel(IQueryable<Product> source, int PageIndex, int PageSize)
{
return new PaginatedList<ProductListViewModel>(source.Select(
p => new ProductListViewModel
{
ProductId = p.Id,
ImageFileName = p.ImageFileNames.First().FileName,
ProductTitle = p.Title,
Price = GetPrice(p.Id)
}),
PageIndex, PageSize);
}
示例8: GetSearchSuggestionAuthorsQuery
public IQueryable<AuthorItemModel> GetSearchSuggestionAuthorsQuery(IQueryable<Author> query)
{
IQueryable<AuthorItemModel> authors = query.Select(ar => new AuthorItemModel
{
Id = ar.AuthorId,
Name = ar.Name,
BornYear = ar.BirthDate != null ? ar.BirthDate.Value.Year : (int?)null,
DeathYear = ar.DeathDate != null ? ar.DeathDate.Value.Year : (int?)null,
Rating = new RatingModel { Value = (double?)ar.Ratings.Average(r => r.Value) ?? 0 },
HasImage = ar.Photo != null,
BooksCount = ar.Books.Count()
});
return authors;
}
示例9: Create
public RestaurantModel Create(DataRow restaurant, IQueryable<DataRow> reviews)
{
return new RestaurantModel()
{
//Url = RestaurantUrl(restaurant),
ID = (int)restaurant["ID"],
Name = restaurant["Name"].ToString(),
Created = (DateTime)restaurant["AddDate"],
Address = _addressModelFactory.Create(
restaurant["City"].ToString(), restaurant["state"].ToString(),
restaurant["country"].ToString(), restaurant["street"].ToString()),
ImgUrl = "../../Content/images/restaurant1.jpg",
Reviews = reviews.Select(rr => _reviewModelFactory.Create(rr))
};
}
示例10: BuildPolyExpression
private IQueryable<int> BuildPolyExpression(IQueryable<int> parent, int depth)
{
if (depth == 0)
return parent;
var expr = parent.Select(x => new {depth, x})
.Where(y => y.x > 10 && y.x/10 > 100)
.OrderBy(z => z.depth)
.ThenBy(q => q.depth)
.ThenByDescending(a => a.x)
.Take(100)
.Skip(10)
.Distinct()
.Cast<int>();
return BuildPolyExpression(expr, depth - 1);
}
示例11: buildInmateVM
// buildInmatesVM is separate from GetActiveInmates to allow creating
// multiple search api methods such as by facility or by sending a
// list of inmate_id's. The SQL query isn't made until the ToList( )
// function is called, so this is still efficient.
private List<InmateVM> buildInmateVM(IQueryable<Inmate> inmateQuery) {
List<InmateVM> inmateList =
inmateQuery.Select(inmate => new InmateVM() {
Id = inmate.inmate_id,
Number = inmate.inmate_number,
FirstName = inmate.Person.person_first_name,
MiddleName = inmate.Person.person_middle_name,
LastName = inmate.Person.person_last_name,
Age= inmate.Person.person_age,
Dob = inmate.Person.person_dob,
FacilityName = inmate.Facility.Facility_Name,
Recieved = inmate.inmate_received_date,
Release = inmate.inmate_scheduled_release_date,
Status = inmate.inmate_status,
}).ToList();
return inmateList;
}
示例12: GetPattern
public static string GetPattern(IQueryable<ChatUserMention> mentions)
{
// Rebuild if nothing is cached
if (_customCachedPattern == null || _customCachedPatternMentions == null)
return UpdatePattern(mentions.ToList());
// Check all the users are in the pattern
var addedCount = mentions.Count(p => !_customCachedPatternMentions.Contains(p.Key));
if (addedCount > 0)
{
return UpdatePattern(mentions.ToList());
}
var currentKeys = mentions.Select(p => p.Key).ToList();
var removedCount = _customCachedPatternMentions.Where(p => !currentKeys.Contains(p)).Count();
return removedCount > 0 ? UpdatePattern(mentions.ToList()) : _customCachedPattern;
}
示例13: PopulateDropDownLists
public async Task PopulateDropDownLists(IQueryable<Author> authors, IQueryable<Collection> collections)
{
(AvailableAuthors as List<SelectListItem>).AddRange(await authors.Select(a => new SelectListItem
{
Text = a.LastName + ", " + a.FirstName,
Value = a.Id.ToString(),
Selected = Document.AuthorId == a.Id
}).ToListAsync());
(AvailableCollections as List<SelectListItem>).AddRange((await collections
.ToListAsync())
.Select(c => new TranslatedViewModel<Collection, CollectionTranslation>(c))
.Select(c => new SelectListItem
{
Selected = c.Entity.Id == Document.CollectionId,
Value = c.Entity.Id.ToString(),
Text = c.Entity.CatalogCode + " - " + "'" + c.Translation.Title + "'"
}));
}
示例14: Select
private IQueryable<ProductWeb> Select(IQueryable<ProductCulture> _PC, int CurrencyID, ApplicationDbContext _c)
{
return _PC.Select(m => new ProductWeb
{
AdditionalInformation = m.AdditionalInformation,
Description = m.Description,
FriendlyUrl = m.FriendlyUrl,
IconPath = m.IconPath,
ProductName = m.ProductName,
ProductID = m.ProductID,
CultureName = m.Culture.Name,
New = m.Product.New,
Featured = m.Product.Featured,
Galleries = m.Product.ProductGalleries.Select(m2 => new ProductGalleryBinding
{
PhotoPath = m2.PhotoPath
}).ToList(),
//TO-DO OPTIMIZE ME
Price = (CurrencyID == 0 || !m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).Any())
? (m.Product.ProductCurrencies.Any()
? m.Product.ProductCurrencies.FirstOrDefault().Price
: 0)
: m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).FirstOrDefault().Price,
PriceOld = (CurrencyID == 0 || !m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).Any())
? (m.Product.ProductCurrencies.Any()
? m.Product.ProductCurrencies.FirstOrDefault().PriceOld
: 0)
: m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).FirstOrDefault().PriceOld,
Sale = (CurrencyID == 0 || !m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).Any())
? (m.Product.ProductCurrencies.Any()
? m.Product.ProductCurrencies.FirstOrDefault().PriceOld > 0
? true
: false
: false)
: (m.Product.ProductCurrencies.Where(p => p.CurrencyID == CurrencyID).FirstOrDefault().PriceOld > 0)
? true
: false
});
}
示例15: GetModelDetail
private ActionResult GetModelDetail(IQueryable<SysUser> model, int pageIndex, int pageSize)
{
var result = model.Select(a => new
{
a.Id,
a.UserId,
a.CreatedDate,
a.DisplayName,
a.MobilePhone,
a.Picture,
a.Enabled,
a.Email,
a.UserName,
DepartmentName = a.SysDepartmentSysUsers.Select(b => b.SysDepartment.DepartmentName),
RoleName = a.SysRoleSysUsers.Select(b => b.SysRole.RoleName),
a.Remark
}).ToPagedList(pageIndex, pageSize);
return Content(JsonConvert.SerializeObject(result));
}