CodeOfChaos.Extensions.EntityFrameworkCore
0.29.2
Prefix Reserved
dotnet add package CodeOfChaos.Extensions.EntityFrameworkCore --version 0.29.2
NuGet\Install-Package CodeOfChaos.Extensions.EntityFrameworkCore -Version 0.29.2
<PackageReference Include="CodeOfChaos.Extensions.EntityFrameworkCore" Version="0.29.2" />
paket add CodeOfChaos.Extensions.EntityFrameworkCore --version 0.29.2
#r "nuget: CodeOfChaos.Extensions.EntityFrameworkCore, 0.29.2"
// Install CodeOfChaos.Extensions.EntityFrameworkCore as a Cake Addin #addin nuget:?package=CodeOfChaos.Extensions.EntityFrameworkCore&version=0.29.2 // Install CodeOfChaos.Extensions.EntityFrameworkCore as a Cake Tool #tool nuget:?package=CodeOfChaos.Extensions.EntityFrameworkCore&version=0.29.2
CodeOfChaos.Extensions.EntityFrameworkCore
CodeOfChaos.Extensions.EntityFrameworkCore
is a library that extends LINQ capabilities in Entity Framework Core. It
introduces conditional extensions for operations like Include
, Where
, OrderBy
, and others. These methods enable
dynamic query building, improving flexibility and readability when working with Entity Framework Core.
Features
Conditional Query Building
Enhance IQueryable
queries with conditional functionality:
- Conditional Includes:
- Dynamically include related entities based on runtime conditions.
- Conditional Filters:
- Apply
Where
clauses only when a condition is met.
- Apply
- Conditional Sorting:
- Apply
OrderBy
clauses conditionally or use optional order expressions.
- Apply
- Conditional Pagination:
- Apply
Take
, including support for ranges.
- Apply
Installation
This library targets .NET 9.0
and requires C# 13.0. Ensure your project meets these requirements before using.
Add the dependency to your project via NuGet:
dotnet add package CodeOfChaos.Extensions.EntityFrameworkCore
Usage
Here’s how you can leverage the library for dynamic query building in Entity Framework Core:
Conditional Include
Dynamically include related entities only when needed:
using Microsoft.EntityFrameworkCore;
var query = dbContext.Users.ConditionalInclude(isAdmin, u => u.Roles);
Conditional Where
Apply a filter based on runtime conditions:
var query = dbContext.Users.ConditionalWhere(filterByEmail, u => u.Email == searchEmail);
Conditional OrderBy
Use conditional sorting:
var query = dbContext.Users.ConditionalOrderBy(applySorting, u => u.LastName);
Or, with a comparer:
var query = dbContext.Users.ConditionalOrderBy(applySorting, u => u.LastName, StringComparer.OrdinalIgnoreCase);
Conditional Take
Limit the results dynamically:
var query = dbContext.Users.ConditionalTake(applyPagination, 50);
Or, with a range:
var query = dbContext.Users.ConditionalTake(applyPagination, ..10);
Contributing
Feel free to fork and contribute to the project by submitting pull requests. When contributing, ensure your changes align with the project’s coding standards.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
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 |
---|---|---|
0.29.2 | 23 | 1/4/2025 |
0.29.0 | 48 | 1/3/2025 |
0.28.2 | 77 | 1/1/2025 |
0.27.1 | 74 | 12/31/2024 |
0.27.0 | 81 | 12/29/2024 |
0.26.0 | 76 | 12/28/2024 |
0.25.0 | 76 | 12/28/2024 |
0.24.3 | 79 | 12/27/2024 |
0.24.2 | 77 | 12/27/2024 |
0.24.1 | 74 | 12/27/2024 |
0.24.0 | 74 | 12/27/2024 |
0.23.1 | 78 | 12/27/2024 |
0.23.0 | 78 | 12/27/2024 |
0.22.2 | 74 | 12/27/2024 |
0.22.0 | 79 | 12/23/2024 |
0.21.0 | 93 | 12/22/2024 |
0.20.0-preview.1 | 43 | 12/21/2024 |