.ToListAsync<T>(Filter)
Async version of .ToList<T>(Filter). Uses EF Core's CountAsync() and ToListAsync() under the hood.
Signature
public static Task<FilterResult<T>> ToListAsync<T>(
this IQueryable<T> query,
Filter filter,
bool getQueryString = false)
where T : class, new()| Parameter | Type | Default | Description |
|---|---|---|---|
filter | Filter | – | Composition object |
getQueryString | bool | false | When true, captures the generated SQL on FilterResult.QueryString |
Pipeline
Whereapplied on the typed query.CountAsync()on the typed query →TotalCount.Orderapplied on the typed query.Pageapplied on the typed query.Selectprojection applied last.ToListAsync()materializes the result.
Warning
Ordering and pagination are applied on the strongly-typed
IQueryable<T> before the select projection so that field names referenced in orders always resolve against the original entity type T.Note
getQueryString: true calls .ToQueryString() which requires an active EF Core database provider.Returns
Task<FilterResult<T>>.
Example
FilterResult<Customer> result = await dbContext.Customers.ToListAsync(filter);
Console.WriteLine($"{result.TotalCount} customers");
foreach (var c in result.Data)
{
Console.WriteLine($"- {c.Name}");
}Capture generated SQL.
var result = await dbContext.Customers.ToListAsync(filter, getQueryString: true);
Console.WriteLine(result.QueryString);Minimal ASP.NET Core endpoint.
app.MapPost("/customers/search", async (Filter filter, AppDbContext db) =>
{
var result = await db.Customers.ToListAsync(filter);
return Results.Ok(result);
});See also
.ToList<T>(Filter)— synchronous variant (and in-memory overload)..ToListAsyncDynamic<T>(Filter)— async dynamic projection.FilterResult<T>shape.