.ToList<T>(Filter)
Materializes a Filter and returns a FilterResult<T> with pagination metadata. Two overloads are available — one for IQueryable<T> (typical EF Core usage) and one for IEnumerable<T> (in-memory pipelines and tests).
IQueryable<T> overload
public static FilterResult<T> ToList<T>(
this IQueryable<T> query,
Filter filter,
bool getQueryString = false)
where T : class, new()IEnumerable<T> overload
In-memory variant — wraps the collection with AsQueryable() then delegates to the typed overload.
public static FilterResult<T> ToList<T>(
this IEnumerable<T> source,
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-equivalent on the typed query →TotalCount.Orderapplied on the typed query.Pageapplied on the typed query.Selectprojection applied last.ToList()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
Passing
getQueryString: true calls .ToQueryString(), which requires an active EF Core database provider. Pure in-memory IEnumerable<T> usage may not support this.Returns
FilterResult<T> with PageNumber, PageSize, PageCount, TotalCount, Data, and optional QueryString.
Example
FilterResult<Product> result = dbContext.Products.ToList(filter);
Console.WriteLine($"page {result.PageNumber} of {result.PageCount}");
Console.WriteLine($"{result.TotalCount} total matches");
foreach (var p in result.Data)
{
Console.WriteLine($"- {p.Name}");
}In-memory variant.
List<Product> source = LoadFromCsv();
FilterResult<Product> result = source.ToList(filter);{
"pageNumber": 1,
"pageSize": 10,
"pageCount": 5,
"totalCount": 42,
"data": [
{ "id": 7, "name": "Laptop Pro", "price": 1299.99, "category": { "name": "Electronics" } }
],
"queryString": null
}See also
.ToListAsync<T>(Filter)— async EF Core variant..ToListDynamic<T>(Filter)— dynamic projection variant.FilterResult<T>shape.