DynamicWhere.ex
DynamicWhere.exv2.1.0·docs

.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()
ParameterTypeDefaultDescription
filterFilterComposition object
getQueryStringboolfalseWhen true, captures the generated SQL on FilterResult.QueryString

Pipeline

  • Where applied on the typed query.
  • CountAsync() on the typed query → TotalCount.
  • Order applied on the typed query.
  • Page applied on the typed query.
  • Select projection 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