本文整理汇总了C#中IQueryable.ToListAsync方法的典型用法代码示例。如果您正苦于以下问题:C# IQueryable.ToListAsync方法的具体用法?C# IQueryable.ToListAsync怎么用?C# IQueryable.ToListAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IQueryable
的用法示例。
在下文中一共展示了IQueryable.ToListAsync方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWrapperValuesForCategories
/// <summary>
/// Generate wrapper values using categories
/// </summary>
/// <param name="collection"> transaction collection</param>
/// <param name="currency"> currency of user wallet</param>
/// <returns> non negative values for all categories</returns>
internal async Task<List<SimpleGraphModel>> GetWrapperValuesForCategories(
IQueryable<Transaction> collection,
Currency currency)
{
var data = await collection.ToListAsync();
return data.Select(transaction => Transformation.ChangeCurrencyForNewTransaction(transaction, currency))
.GroupBy(transaction => transaction.Category.Name)
.Select(
group =>
new SimpleGraphModel
{
Label = group.Key,
Value = group.Sum(transaction => Math.Abs(transaction.Amount))
})
.ToList();
}
示例2: 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 + "'"
}));
}
示例3: FilterEventsAsync
internal static async Task<IQueryable<Event>> FilterEventsAsync(SportDataContext ctx, string domain, IQueryable<Event> evQuery)
{
domain = domain ?? "";
var site = await ctx.Sites
.Include(s => s.Tags)
.FirstOrDefaultAsync(s => s.Domain.ToUpper() == domain.ToUpper());
if (site != null)
{
var eventsTags = await ctx.Tags.Include("Event").Include("Event.Event").OfType<EventTag>().ToListAsync();
var seriesTags = await ctx.Tags.OfType<SeriesTag>().Include(t => t.Series).ToListAsync();
var events = eventsTags.Where(t => site.Tags.Contains(t)).Select(t=>t.Event.Event).ToList();
var series = seriesTags.Where(t => site.Tags.Contains(t)).Select(t => t.Series).ToList();
var query = await evQuery.ToListAsync();
evQuery = query.Where(e => events.Contains(e) || e.Series.Any(s => series.Contains(s))).AsQueryable();
}
return evQuery;
}
示例4: FilterRequestsAsync
public async Task<IEnumerable<Request>> FilterRequestsAsync(RequestSearch specifiedRequest, IQueryable<Request> requests)
{
if (specifiedRequest.Description != null)
{
requests = requests.Where(x => x.Description.Contains(specifiedRequest.Description));
}
if (specifiedRequest.Location != null)
{
requests = requests.Where(x => x.Location.Contains(specifiedRequest.Location));
}
if (specifiedRequest.NullableCreatedDate != null)
{
requests = requests.Where(x => x.CreatedDate == specifiedRequest.NullableCreatedDate);
}
if (specifiedRequest.NullableEndDate != null)
{
requests = requests.Where(x => x.EndDate == specifiedRequest.NullableEndDate);
}
if (specifiedRequest.RequestStatus != RequestStatus.All)
{
switch (specifiedRequest.RequestStatus)
{
case RequestStatus.Unassigned:
requests = requests.Where(x => x.Completed == false && !x.AssigneeId.HasValue);
break;
case RequestStatus.Assigned:
requests = requests.Where(x => x.Completed == false && x.AssigneeId.HasValue);
break;
case RequestStatus.Completed:
requests = requests.Where(x => x.Completed == true);
break;
default:
throw new ArgumentException("A valid request status was not selected.");
}
}
return await requests.ToListAsync();
}
示例5: GetGraphForMonthLastYear
/// <summary>
/// Returns graph data for months in last year
/// </summary>
/// <param name="collection"></param>
/// <param name="currency"> currency of user wallet</param>
/// <returns>Graph data for every month in last year</returns>
private async Task<GraphWithDescriptionModel> GetGraphForMonthLastYear(
IQueryable<Transaction> collection,
Currency currency)
{
var data = await collection.ToListAsync();
var result =
data.Select(transaction => Transformation.ChangeCurrencyForNewTransaction(transaction, currency))
.GroupBy(transaction => new {transaction.Date.Month, transaction.Date.Year}).Select(
group =>
new SimpleGraphModel
{
Label = group.Key.Month + DashBoardResource.MonthDelimiter + group.Key.Year,
Value = group.Sum(transaction => transaction.Amount)
})
.ToList();
return new GraphWithDescriptionModel
{
Description = DashBoardResource.LastYearTabDescription,
GraphData = result
};
}