@@ -14,15 +14,118 @@ offering:
1414- ** Better Integration:** More intuitive integration with your existing .NET applications.
1515
1616## Features
17-
17+ - ** Dynamic Filtering:** Easily apply dynamic filtering to your queries.
18+ - ** Dynamic Ordering:** Easily apply dynamic ordering to your queries.
19+ - ** Pagination Support:** Simplified methods for paginating your data.
20+ - ** Custom Configurations:** Extend and customize Gridify configurations effortlessly.
21+ - ** Global Injection:** Inject configurations globally for consistency across your application.
22+ - ** Support for Various Data Types:** Handle multiple data types seamlessly.
1823## Getting Started
1924To get started, install the package via NuGet:
2025
2126``` bash
2227dotnet add package Pandatech.Gridify.Extensions
2328```
2429
30+ To enable Gridify support and register custom mapping classes, call the AddGridify method on the WebApplicationBuilder.
31+ You can specify which assemblies to search for configurations.
32+ ``` csharp
33+ builder .AddGridify (params Assembly [] assemblies );
34+ ```
35+
2536## Usage
37+ ** Creating Mappings for Your Entities:**
38+ To efficiently filter and query your Book entity using Gridify, you need to create a mapping class that extends GridifyMapper<T >.
39+ This class will define how each property in your Book entity should be mapped.
40+
41+ Here’s an example of how to set up the Book entity and its corresponding mapping class:
42+ ``` csharp
43+ public class Book
44+ {
45+ public Guid BookId { get ; set ; } = Guid .NewGuid ();
46+ public string Title { get ; set ; }
47+ public DateTime Date { get ; set ; }
48+ public int Count { get ; set ; }
49+ public long CountLong { get ; set ; }
50+ public decimal CountDecimal { get ; set ; }
51+ public ICollection <Book > Books { get ; set ; }
52+ public Book OtherBook { get ; set ; }
53+ }
54+
55+ public class BookMapper : GridifyMapper <Book >
56+ {
57+ public BookMapper ()
58+ {
59+ // Map "book-id" to BookId property
60+ AddMap (" book-id" , x => x .BookId );
61+
62+ // Map "count" to Count property with an optional converter
63+ AddMap (" count" , x => x .Count , x => x .ToLower ());
64+
65+ // Map "count-long" to CountLong property
66+ AddMap (" count-long" , x => x .CountLong );
67+
68+ // Map "count-decimal" to CountDecimal property
69+ AddMap (" count-decimal" , x => x .CountDecimal );
70+
71+ // Map "other-dates" to the Date property of the Books collection
72+ AddMap (" other-dates" , x => x .Books .Select (b => b .Date ));
73+
74+ // Map "other-book-id" to the BookId property of the OtherBook property
75+ AddMap (" other-book-id" , x => x .OtherBook .BookId );
76+ }
77+ }
78+
79+ ```
80+
81+ Adding Converters
82+
83+ You can specify a converter function as the third parameter in the AddMap method to transform the value before it is used.
84+ This is useful for custom data manipulation and formatting.
85+
86+ ** Using Extension Methods**
87+ With Pandatech.GridifyExtensions, you can use several extension methods for filtering, sorting, and paging defined on the IQueryable<T > interface. Here are some examples:
88+ Filtering, Sorting, and Paging
89+
90+ Use FilterOrderAndGetPagedAsync to apply filtering, sorting, and paging to your queries:
91+ ``` csharp
92+ public static async Task < PagedResponse < TDto >> FilterOrderAndGetPagedAsync <TEntity , TDto >(
93+ this IQueryable < TEntity > query , GridifyQueryModel model ,
94+ Expression < Func < TEntity , TDto >> selectExpression , CancellationToken cancellationToken = default )
95+
96+ public static Task < PagedResponse < TEntity >> FilterOrderAndGetPagedAsync <TEntity >(
97+ this IQueryable < TEntity > query , GridifyQueryModel model , CancellationToken cancellationToken = default )
98+ ```
99+
100+ Example Usage:
101+ ``` csharp
102+ var pagedResponse = await dbContext .Books
103+ .FilterOrderAndGetPagedAsync (new GridifyQueryModel { PageSize = 10 , Page = 1 }, cancellationToken );
104+ ```
105+
106+ Use ColumnDistinctValuesAsync to get distinct values of a specific column:
107+ ``` csharp
108+ public static async Task < PagedResponse < object >> ColumnDistinctValuesAsync <TEntity >(
109+ this IQueryable < TEntity > query , ColumnDistinctValueQueryModel model ,
110+ Func < byte [], string > ? decryptor = default , CancellationToken cancellationToken = default )
111+
112+ ```
113+ Example Usage:
114+ ``` csharp
115+ var distinctValues = await dbContext .Books
116+ .ColumnDistinctValuesAsync (new ColumnDistinctValueQueryModel { PropertyName = " Title" }, cancellationToken );
117+ ```
118+
119+ Use AggregateAsync to perform aggregation operations on your data:
120+ ``` csharp
121+ public static async Task < object > AggregateAsync <TEntity >(
122+ this IQueryable < TEntity > query , AggregateQueryModel model , CancellationToken cancellationToken = default )
123+ ```
124+ Example Usage:
125+ ``` csharp
126+ var aggregateResult = await dbContext .Books
127+ .AggregateAsync (new AggregateQueryModel { AggregateType = AggregateType .Sum , PropertyName = " count" }, cancellationToken );
128+ ```
26129
27130## License
28131
0 commit comments