Sindika.AspNet.QueryBuilder
1.2.2
dotnet add package Sindika.AspNet.QueryBuilder --version 1.2.2
NuGet\Install-Package Sindika.AspNet.QueryBuilder -Version 1.2.2
<PackageReference Include="Sindika.AspNet.QueryBuilder" Version="1.2.2" />
<PackageVersion Include="Sindika.AspNet.QueryBuilder" Version="1.2.2" />
<PackageReference Include="Sindika.AspNet.QueryBuilder" />
paket add Sindika.AspNet.QueryBuilder --version 1.2.2
#r "nuget: Sindika.AspNet.QueryBuilder, 1.2.2"
#addin nuget:?package=Sindika.AspNet.QueryBuilder&version=1.2.2
#tool nuget:?package=Sindika.AspNet.QueryBuilder&version=1.2.2
Sindika.AspNet QueryBuilder Library
The Sindika.AspNet QueryBuilder is a robust library designed to streamline the process of building dynamic queries for .NET applications. It is particularly focused on enabling flexible and efficient data filtering, sorting, and pagination for use with Entity Framework Core and other IQueryable providers.
Features
Dynamic Filtering
- Supports complex filters with various operators:
- Equality (
eq
), Not Equal (ne
), Less Than (lt
), Greater Than (gt
) - Between (
bt
), In (in
), Like (like
) - Null (
nu
), Not Null (nn
), etc.
- Equality (
- Enables nested and dynamic property access for complex object hierarchies.
Search Functionality
- Dynamically generates search expressions for string-based properties using a case-insensitive
Contains
method.
Sorting Capabilities
- Applies multi-level sorting dynamically based on the provided sort criteria.
Pagination
- Provides efficient mechanisms to paginate query results.
- Includes metadata such as:
- Total items
- Current page
- Total pages
- Supports index-based item enumeration.
Custom Tagging
- Adds debugging context to EF Core queries using
TagWith
for easier tracing in logs.
Reusable Utilities
- Simplifies pagination response generation with methods like
GenerateResponse
andGenerateResponseWithIndex
.
Error Handling
- Includes robust exception handling for invalid input and unsupported scenarios.
Installation
To use the Sindika.AspNet QueryBuilder library in your project, install the NuGet package:
dotnet add package Sindika.AspNet.QueryBuilder
Usage
Dynamic Query Building
var paginationQuery = new PaginationQuery
{
Filters = new List<Filter>
{
new Filter { Field = "Name", Operator = "eq", Value = "John Doe" },
new Filter { Field = "Age", Operator = "gt", Value = 30 }
},
Sorts = new List<Sort>
{
new Sort { Field = "CreatedDate", Direction = "desc" }
},
Pagination = new Pagination
{
Page = 1,
PageSize = 10
}
};
var query = dbContext.Users.AsQueryable();
var expressionBuilder = new ExpressionBuilder();
var result = await expressionBuilder.BuildPaginationQuery(paginationQuery, query);
Console.WriteLine($"Total Items: {result.Count}");
foreach (var item in result.Items)
{
Console.WriteLine(item);
}
API Reference
Classes
ExpressionBuilder
BuildPaginationQuery<T>(PaginationQuery, IQueryable<T>)
BuildDynamicFilter<T>(PaginationQuery)
ApplySorting<T>(IQueryable<T>, PaginationQuery)
BuildDynamicPredicate<T>(Dictionary<string, object>)
PaginationUtils
TryGetFromHttpContext(HttpContext)
GenerateResponse<T>(PaginationQuery, List<T>, long)
GenerateResponseWithIndex<T>(PaginationQuery, List<T>, long)
Contributing
Contributions are welcome! Please submit issues or pull requests on the GitHub repository.
Authors
Developed by Sindika Development Team.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.EntityFrameworkCore (>= 9.0.0)
- Newtonsoft.Json (>= 13.0.3)
- Sindika.AspNet.Common (>= 1.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.