PK.EntityFramework.Extensions.GetItems
1.0.4
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package PK.EntityFramework.Extensions.GetItems --version 1.0.4
NuGet\Install-Package PK.EntityFramework.Extensions.GetItems -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PK.EntityFramework.Extensions.GetItems" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PK.EntityFramework.Extensions.GetItems" Version="1.0.4" />
<PackageReference Include="PK.EntityFramework.Extensions.GetItems" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PK.EntityFramework.Extensions.GetItems --version 1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: PK.EntityFramework.Extensions.GetItems, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package PK.EntityFramework.Extensions.GetItems@1.0.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PK.EntityFramework.Extensions.GetItems&version=1.0.4
#tool nuget:?package=PK.EntityFramework.Extensions.GetItems&version=1.0.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
PK.EntityFramework.Extensions.GetItems
A simple, expressive way to paginate, filter, and sort data in Entity Framework. Works great with APIs and directly in your business logic.
Installation
dotnet add package PK.EntityFramework.Extensions.GetItems
Quick Start
// Define your filterable properties
public enum BookPropertyNames { Name, PublishedOn, AuthorName }
// Map enum values to property paths
static string[] PropertyNameMapper(BookPropertyNames field) => field switch
{
BookPropertyNames.Name => [nameof(Book.Name)],
BookPropertyNames.PublishedOn => [nameof(Book.PublishedOn)],
BookPropertyNames.AuthorName => [nameof(Book.Author), nameof(Author.Name)],
_ => throw new ArgumentOutOfRangeException()
};
// Create a request
var request = new BaseGetItemsRequest<BookPropertyNames, Guid>
{
Page = 1,
Count = 10,
Filters = [
new() { Field = BookPropertyNames.Name, Operator = FilterOperatorEnum.Contains, Value = "Great" }
],
Sort = [
new() { Field = BookPropertyNames.PublishedOn, Order = OrderByEnum.Descending }
]
};
// Execute with IDbContextFactory
var result = await dbContextFactory.GetItems(
ctx => ctx.Books.AsQueryable(),
request,
b => b.Id,
PropertyNameMapper
);
// Or directly on IQueryable (Cheap/None pagination modes only)
var result = await dbContext.Books.GetItems(request, b => b.Id, PropertyNameMapper);
// result.Items, result.TotalCount, result.Page, result.TotalPages
Features
- Pagination — Three modes: Expensive (full count), Cheap (has next page), None
- Filtering — Rich operators with AND/OR logic and nested filters
- Sorting — Multi-level sorting on any property
- ID filtering — Include/exclude specific IDs with
IdsandExceptIds - Nested properties — Filter/sort through relationships
- Type-safe — Enum-based property names, compile-time checking
- Query debugging — Inspect generated expression trees
Pagination Modes
var options = new GetItemsOptions
{
PaginationHandling = PaginationHandlingEnum.Cheap // default
};
| Mode | Description | Returns |
|---|---|---|
Cheap |
Fetches N+1 items to check next page | HasNextPage (default) |
Expensive |
Runs parallel COUNT query | TotalCount, TotalPages |
None |
No pagination metadata | Items only |
Note:
Expensivemode requiresIDbContextFactory. UseCheaporNonewith directIQueryableextensions.
Filter Operators
| Operator | Description |
|---|---|
Eq, Neq |
Equal / Not equal |
Lt, Lte, Gt, Gte |
Comparison operators |
StartsWith, EndsWith, Contains |
String matching |
ContainsAll, NotContains |
Collection operations |
Flag, AnyFlag, NotFlag, NotAnyFlag |
Bitwise flag operations |
Request Options
var request = new BaseGetItemsRequest<PropertyEnum, Guid>
{
// Pagination
Page = 1,
Count = 25,
Skip = 0, // Additional skip offset
// ID filtering
Ids = [guid1, guid2], // Include only these IDs
ExceptIds = [guid3], // Exclude these IDs
// Filters and sorting
Filters = [...],
Sort = [...],
// Optimization: pass cached total to skip COUNT query
TotalCount = cachedTotal
};
Property Mapping
Map enum values to property paths, including nested properties:
public static string[] PropertyNameMapper(BookPropertyNames field) => field switch
{
BookPropertyNames.Name => [nameof(Book.Name)],
BookPropertyNames.PublishedOn => [nameof(Book.PublishedOn)],
BookPropertyNames.AuthorName => [nameof(Book.Author), nameof(Author.Name)],
_ => throw new ArgumentOutOfRangeException()
};
Response
public class PaginatedData<T>
{
public T[] Items { get; }
public int Page { get; }
public int Count { get; }
public long? TotalCount { get; } // Expensive mode only
public int? TotalPages { get; } // Expensive mode only
public bool? HasNextPage { get; } // Cheap mode only
public string? QueryDebugView { get; } // When DebugQuery = true
}
Query Debugging
Enable debug mode to inspect the generated expression:
var options = new GetItemsOptions { DebugQuery = true };
var result = await factory.GetItems(ctx => ctx.Books, request, b => b.Id, mapper, options);
Console.WriteLine(result.QueryDebugView);
// Output:
// DbSet<Book>()
// .Where(b => b.Name.Contains("Great"))
// .OrderByDescending(b => b.PublishedOn)
Example Project
Check out EntityFramework.Extensions.GetItems.Example for a complete working API.
cd Source/EntityFramework.Extensions.GetItems.Example
dotnet run
# Open http://localhost:5000/scalar/v1
License
MIT
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.22)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.4 | 89 | 1/13/2026 |
| 1.1.4-preview.28 | 39 | 1/13/2026 |
| 1.1.3 | 84 | 1/13/2026 |
| 1.1.3-preview.27 | 39 | 1/13/2026 |
| 1.1.3-preview.25 | 41 | 1/13/2026 |
| 1.1.2 | 78 | 1/13/2026 |
| 1.1.2-preview.24 | 42 | 1/13/2026 |
| 1.1.2-preview.22 | 34 | 1/13/2026 |
| 1.1.1 | 76 | 1/13/2026 |
| 1.1.1-preview.21 | 35 | 1/13/2026 |
| 1.1.1-preview.20 | 33 | 1/13/2026 |
| 1.1.1-preview.18 | 41 | 1/13/2026 |
| 1.1.0 | 83 | 1/13/2026 |
| 1.1.0-preview.17 | 34 | 1/13/2026 |
| 1.1.0-preview.15 | 37 | 1/13/2026 |
| 1.0.4 | 156 | 12/26/2025 |
| 1.0.4-preview.14 | 43 | 1/13/2026 |
| 1.0.4-preview.12 | 93 | 12/26/2025 |
| 1.0.3-preview.11 | 95 | 12/26/2025 |
| 1.0.2 | 186 | 12/25/2025 |
| 1.0.2-preview.7 | 129 | 12/25/2025 |
| 1.0.2-preview.5 | 127 | 12/25/2025 |
| 1.0.1 | 175 | 12/25/2025 |
| 1.0.1-preview.4 | 126 | 12/25/2025 |