Pandatech.GridifyExtensions
1.5.4
See the version list below for details.
dotnet add package Pandatech.GridifyExtensions --version 1.5.4
NuGet\Install-Package Pandatech.GridifyExtensions -Version 1.5.4
<PackageReference Include="Pandatech.GridifyExtensions" Version="1.5.4" />
paket add Pandatech.GridifyExtensions --version 1.5.4
#r "nuget: Pandatech.GridifyExtensions, 1.5.4"
// Install Pandatech.GridifyExtensions as a Cake Addin #addin nuget:?package=Pandatech.GridifyExtensions&version=1.5.4 // Install Pandatech.GridifyExtensions as a Cake Tool #tool nuget:?package=Pandatech.GridifyExtensions&version=1.5.4
Pandatech.GridifyExtensions
Welcome to Pandatech.GridifyExtensions! This library builds on top of the popular Gridify package, adding new functionalities and simplifying its use for data filtering and pagination in .NET applications.
Why Use Pandatech.GridifyExtensions?
Gridify is a powerful tool for querying and filtering data. However, integrating it into your projects can sometimes involve repetitive code and extra setup. Pandatech.GridifyExtensions aims to make your development process smoother by offering:
- Extended Functionality: Additional methods to handle common data filtering scenarios.
- Simplified API: Streamlined usage to minimize boilerplate code and enhance readability.
- Better Integration: More intuitive integration with your existing .NET applications.
Features
- Dynamic Filtering: Easily apply dynamic filtering to your queries.
- Dynamic Ordering: Easily apply dynamic ordering to your queries.
- Pagination Support: Simplified methods for paginating your data.
- Custom Configurations: Extend and customize Gridify configurations effortlessly.
- Global Injection: Inject configurations globally for consistency across your application.
- Support for Various Data Types: Handle multiple data types seamlessly.
Getting Started
To get started, install the package via NuGet:
dotnet add package Pandatech.Gridify.Extensions
To enable Gridify support and register custom mapping classes, call the AddGridify method on the WebApplicationBuilder. You can specify which assemblies to search for configurations.
builder.AddGridify(params Assembly[] assemblies);
Usage
Creating Mappings for Your Entities: To efficiently filter and query your Book entity using Gridify, you need to create a mapping class that extends FilterMapper<T>. This class will define how each property in your Book entity should be mapped.
Here’s an example of how to set up the Book entity and its corresponding mapping class:
public class Book
{
public Guid BookId { get; set; } = Guid.NewGuid();
public string Title { get; set; }
public DateTime Date { get; set; }
public int Count { get; set; }
public long CountLong { get; set; }
public decimal CountDecimal { get; set; }
public ICollection<Book> Books { get; set; }
public Book OtherBook { get; set; }
}
public class BookMapper : FilterMapper<Book>
{
public BookMapper()
{
// Map "book-id" to BookId property
AddMap("book-id", x => x.BookId);
// Map "count" to Count property with an optional converter
AddMap("count", x => x.Count, x => x.ToLower());
// Map "count-long" to CountLong property
AddMap("count-long", x => x.CountLong);
// Map "count-decimal" to CountDecimal property
AddMap("count-decimal", x => x.CountDecimal);
// Map "other-dates" to the Date property of the Books collection
AddMap("other-dates", x => x.Books.Select(b => b.Date));
// Map "other-book-id" to the BookId property of the OtherBook property
AddMap("other-book-id", x => x.OtherBook.BookId);
}
}
Adding Converters
You can specify a converter function as the third parameter in the AddMap method to transform the value before it is used. This is useful for custom data manipulation and formatting.
Using Extension Methods With Pandatech.GridifyExtensions, you can use several extension methods for filtering, sorting, and paging defined on the IQueryable<T> interface. Here are some examples: Filtering, Sorting, and Paging
Use FilterOrderAndGetPagedAsync to apply filtering, sorting, and paging to your queries:
public static async Task<PagedResponse<TDto>> FilterOrderAndGetPagedAsync<TEntity, TDto>(
this IQueryable<TEntity> query, GridifyQueryModel model,
Expression<Func<TEntity, TDto>> selectExpression, CancellationToken cancellationToken = default)
public static Task<PagedResponse<TEntity>> FilterOrderAndGetPagedAsync<TEntity>(
this IQueryable<TEntity> query, GridifyQueryModel model, CancellationToken cancellationToken = default)
Example Usage:
var pagedResponse = await dbContext.Books
.FilterOrderAndGetPagedAsync(new GridifyQueryModel { PageSize = 10, Page = 1 }, cancellationToken);
'GridifyQueryModel' by default has PageSize validation with 500 records. If you want to ignore this validation, you should pass bool 'false' into its constructor, otherwise the validation will be applied into it, and you will not be able to get more records.
var gridifyQueryModel = new GridifyQueryModel(false) { PageSize = 10, Page = 1 };
As an alternative solution you can use 'SetMaxPageSize()' method to set PageSize into 'int.MaxValue' instead of using constructor parameter.
gridifyQueryModel.SetMaxPageSize();
Use ColumnDistinctValuesAsync to get distinct values of a specific column:
public static async Task<CursoredResponse<object>> ColumnDistinctValuesAsync<TEntity>(
this IQueryable<TEntity> query, ColumnDistinctValueCursoredQueryModel model,
Func<byte[], string>? decryptor = default, CancellationToken cancellationToken = default)
Example Usage:
var distinctValues = await dbContext.Books
.ColumnDistinctValuesAsync(new ColumnDistinctValueCursoredQueryModel { PropertyName = "Title", PageSize=50, Filter="Title>abc" }, cancellationToken);
Use AggregateAsync to perform aggregation operations on your data:
public static async Task<object> AggregateAsync<TEntity>(
this IQueryable<TEntity> query, AggregateQueryModel model, CancellationToken cancellationToken = default)
Example Usage:
var aggregateResult = await dbContext.Books
.AggregateAsync(new AggregateQueryModel { AggregateType = AggregateType.Sum, PropertyName = "count" }, cancellationToken);
License
Pandatech.GridifyExtensions is licensed under the MIT License.
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. |
-
net8.0
- Gridify.EntityFramework (>= 2.14.2)
- Microsoft.AspNetCore.OpenApi (>= 8.0.6)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Pandatech.GridifyExtensions:
Package | Downloads |
---|---|
Pandatech.ResponseCrafter
Handling exceptions, custom Dtos. |
|
Pandatech.SharedKernel.Postgres
Pandatech.SharedKernel.Postgres simplifies PostgreSQL integration in ASP.NET Core applications by providing utilities for Entity Framework Core setup, health checks, and other enhancements. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.0.0 | 152 | 11/21/2024 |
1.7.0 | 81 | 11/14/2024 |
1.6.5 | 89 | 11/8/2024 |
1.6.4 | 87 | 11/7/2024 |
1.6.3 | 82 | 11/6/2024 |
1.6.2 | 134 | 10/2/2024 |
1.6.1 | 93 | 10/2/2024 |
1.6.0 | 84 | 9/24/2024 |
1.5.4 | 122 | 7/29/2024 |
1.5.3 | 90 | 7/24/2024 |
1.5.2 | 79 | 7/24/2024 |
1.5.1 | 142 | 7/18/2024 |
1.5.0 | 99 | 7/18/2024 |
1.4.2 | 119 | 7/2/2024 |
1.4.1 | 91 | 7/2/2024 |
1.4.0 | 138 | 6/28/2024 |
1.3.8 | 118 | 6/24/2024 |
1.3.6 | 120 | 6/24/2024 |
1.3.5 | 96 | 6/24/2024 |
1.3.4 | 100 | 6/24/2024 |
1.3.3 | 100 | 6/24/2024 |
1.3.2 | 104 | 6/24/2024 |
1.3.1 | 187 | 6/21/2024 |
1.3.0 | 121 | 6/18/2024 |
1.2.2 | 114 | 6/17/2024 |
1.2.1 | 113 | 6/17/2024 |
1.2.0 | 111 | 6/17/2024 |
1.1.0 | 133 | 6/13/2024 |
1.0.9 | 115 | 6/13/2024 |
1.0.8 | 110 | 6/13/2024 |
1.0.7 | 110 | 6/13/2024 |
1.0.6 | 111 | 6/13/2024 |
1.0.5 | 119 | 6/13/2024 |
1.0.4 | 109 | 6/13/2024 |
1.0.3 | 124 | 6/13/2024 |
1.0.2 | 111 | 6/12/2024 |
1.0.1 | 109 | 6/12/2024 |
1.0.0 | 108 | 6/12/2024 |
Apply filter new overload