### Install and Run Documentation Locally with Yarn Source: https://alirezanet.github.io/Gridify/contribution This snippet shows the commands to install project dependencies and start the documentation development server locally using Yarn. Ensure Yarn is installed globally. ```shell yarn install yarn dev ``` -------------------------------- ### Install and Run Documentation Locally with npm Source: https://alirezanet.github.io/Gridify/contribution This snippet details the commands required to install project dependencies and launch the documentation development server locally using npm. Node.js and npm must be installed. ```shell npm install npm run dev ``` -------------------------------- ### Install Gridify .NET Package Source: https://alirezanet.github.io/Gridify/guide/getting-started Installs the core Gridify package for .NET applications via the NuGet package manager. This package provides the fundamental gridification capabilities. ```shell dotnet add package Gridify --version 2.17.0 ``` -------------------------------- ### Install Gridify Client JavaScript/TypeScript Package Source: https://alirezanet.github.io/Gridify/guide/getting-started Installs the gridify-client package for JavaScript or TypeScript environments. This lightweight client library allows for creating dynamic queries on the client side for server-side operations. ```shell npm i gridify-client ``` -------------------------------- ### Install Gridify.EntityFramework via Package Manager Source: https://alirezanet.github.io/Gridify/guide/extensions/entityframework Installs the Gridify.EntityFramework package version 2.17.0 using the Package Manager Console. This package provides asynchronous Gridify methods for Entity Framework. ```shell Install-Package Gridify.EntityFramework -Version 2.17.0 ``` -------------------------------- ### Install Gridify.EntityFramework via .NET CLI Source: https://alirezanet.github.io/Gridify/guide/extensions/entityframework Installs the Gridify.EntityFramework package version 2.17.0 using the .NET CLI. This package enhances Entity Framework queries with Gridify's capabilities. ```shell dotnet add package Gridify.EntityFramework --version 2.17.0 ``` -------------------------------- ### Import Gridify Namespace C# Source: https://alirezanet.github.io/Gridify/guide/getting-started Demonstrates how to import the Gridify namespace in C# code. This is required to access the Gridify classes and static extension methods after installing the package. ```csharp using Gridify; ``` -------------------------------- ### Install Gridify Elasticsearch Package Source: https://alirezanet.github.io/Gridify/guide/getting-started Installs the Gridify.Elasticsearch package, enabling Gridify integration with Elasticsearch. This package is necessary for using Gridify's features with Elasticsearch data stores. ```shell dotnet add package Gridify.Elasticsearch --version 2.17.0 ``` -------------------------------- ### Example Output of Gridify Query Source: https://alirezanet.github.io/Gridify/guide/extensions/gridify-client Shows the JSON output generated by the Gridify Client library after building a dynamic query. This represents the structure sent to the server. ```json { "page": 2, "pageSize": 10, "orderBy": "name desc", "filter": "(age<50|name^A),isActive=true" } ``` -------------------------------- ### Install Gridify NuGet Package via .NET Core CLI Source: https://alirezanet.github.io/Gridify/v1 This command installs the Gridify NuGet package using the .NET Core Command Line Interface. It's a cross-platform alternative to the Package Manager Console for managing NuGet packages. ```bash dotnet add package Gridify ``` -------------------------------- ### Install Gridify NuGet Package via Package Manager Console Source: https://alirezanet.github.io/Gridify/v1 This command installs the Gridify NuGet package using the Package Manager Console in Visual Studio. This is a standard way to add external libraries to a .NET project. ```powershell Install-Package Gridify ``` -------------------------------- ### Install Gridify.Elasticsearch Package Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch Installs the Gridify.Elasticsearch package using Package Manager or .NET CLI. The current version is 2.17.0. This package provides extension methods for integrating Gridify with Elasticsearch. ```shell Install-Package Gridify.Elasticsearch -Version 2.17.0 ``` ```shell dotnet add package Gridify.Elasticsearch --version 2.17.0 ``` -------------------------------- ### Build a Dynamic Query with GridifyClient Source: https://alirezanet.github.io/Gridify/guide/extensions/gridify-client An example of using the Gridify Client library in TypeScript to construct a dynamic query. It includes setting pagination, ordering, filtering with logical groups, and applying conditions. ```typescript import { GridifyQueryBuilder, ConditionalOperator as op } from "gridify-client"; const query = new GridifyQueryBuilder() .setPage(2) .setPageSize(10) .addOrderBy("name", true) .startGroup() .addCondition("age", op.LessThan, 50) .or() .addCondition("name", op.StartsWith, "A") .endGroup() .and() .addCondition("isActive", op.Equal, true) .build(); console.log(query); ``` -------------------------------- ### Example SQL Query with Parameter Source: https://alirezanet.github.io/Gridify/guide/extensions/entityframework Demonstrates a SQL query generated with a parameter, typical of Entity Framework interactions enhanced by Gridify. This query filters users by name. ```sql DECLARE @__Value_0 nvarchar(4000) = N'vahid'; SELECT [u].[Id], [u].[CreateDate], [u].[FkGuid], [u].[Name] FROM [Users] AS [u] WHERE [u].[Name] = @__Value_0 ``` -------------------------------- ### Directly Parsing Ordering Strings (C#) Source: https://alirezanet.github.io/Gridify/guide/syntax Shows how to parse an ordering string into a collection of ordering objects using the ParseOrderings method. The example iterates through the parsed orderings and prints the MemberName of each. ```csharp var orderings = SyntaxTree.ParseOrderings("Id desc, FirstName asc, LastName"); foreach (var ordering in orderings) { Console.WriteLine(ordering.MemberName); } // Id // FirstName // LastName ``` -------------------------------- ### Build Query with Conditions and Ordering - C# Source: https://alirezanet.github.io/Gridify/guide/queryBuilder Demonstrates how to use the QueryBuilder class to manually construct a query with filtering conditions and ordering. This example initializes a QueryBuilder for a 'Person' type, adds a name condition and an age/id ordering, and then applies the built query to a collection. ```csharp var builder = new QueryBuilder() .AddCondition("name=John") .AddOrderBy("age, id"); var query = builder.Build(persons); ``` -------------------------------- ### Complete Request Sample for Gridify API Source: https://alirezanet.github.io/Gridify/v1 This example shows a complete URL request sample to an API endpoint that uses Gridify. It includes query parameters for page size, page number, sorting direction and field, and filtering by age. This illustrates how client applications can send complex data manipulation requests. ```text http://exampleDomain.com/api/GetPersons?pageSize=100&page=1&sortBy=FirstName&isSortAsc=false&filter=Age%3D%3D10 ``` -------------------------------- ### Basic GridifyQuery Configuration in C# Source: https://alirezanet.github.io/Gridify/v1 This C# example shows the manual creation and configuration of a GridifyQuery object. It specifies filtering by 'FirstName' to 'John', disabling ascending sort, setting the page number to 1, page size to 20, and sorting by 'LastName'. This object is then used with the Gridify extension method on a data source. ```csharp // usually, we don't need to create this object manually // for example, we get this object as a parameter from our API Controller var gQuery = new GridifyQuery() { Filter = "FirstName==John", IsSortAsc = false, Page = 1, PageSize = 20, SortBy = "LastName" }; Paging pData = myDbContext.Persons // we can use Any list or repository or EntityFramework context .Gridify(gQuery); // Filter,Sort & Apply Paging // pData.TotalItems => Count persons with 'John', First name // pData.Items => First 20 Persons with 'John', First Name ``` -------------------------------- ### AutoMapper ProjectTo with Gridify Filtering, Ordering, and Paging Source: https://alirezanet.github.io/Gridify/guide/autoMapper Illustrates a complete data manipulation workflow using Gridify for filtering, ordering, and paging, followed by AutoMapper's ProjectTo for projection. This example utilizes GridifyQueryable and constructs a Paging object containing the projected DTOs. ```csharp QueryablePaging qp = personRepo.GridifyQueryable(gridifyQuery); var result = new Paging(qp.Count, qp.Query.ProjectTo().ToList()); ``` -------------------------------- ### API Request Sample Ignoring GridifyQuery Source: https://alirezanet.github.io/Gridify/v1 This example demonstrates a simplified API request where the GridifyQuery object is not explicitly provided in the URL. In such cases, Gridify would likely apply default settings or no filtering/sorting/pagination, returning a default dataset. ```text http://exampleDomain.com/api/GetPersons ``` -------------------------------- ### Inject and Use GridifyMapper with QueryBuilder in C# Source: https://alirezanet.github.io/Gridify/guide/dependency-injection This C# controller example demonstrates injecting `IGridifyMapper` and using `QueryBuilder` to apply Gridify queries. The `UseCustomMapper` method is called to integrate the injected mapper, allowing for flexible query construction before building the final result from the data source. This approach offers more granular control over query execution. ```csharp public class WeatherForecastController : ControllerBase { private readonly IGridifyMapper _mapper; public WeatherForecastController(IGridifyMapper mapper) { _mapper = mapper; } [HttpGet(Name = "GetWeatherForecast")] public IEnumerable Get([FromQuery] GridifyQuery query) { var result = GetWeatherForecasts(); var queryBuilder = new QueryBuilder() .UseCustomMapper(_mapper) .AddQuery(query); return queryBuilder.Build(result); } } ``` -------------------------------- ### Define Sample Entities for GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Defines sample C# classes 'Person' and 'Contact' to demonstrate how GridifyMapper can map string-based field names to entity properties. These classes serve as the data structure for examples of GridifyMapper usage. ```csharp public class Person { public string UserName { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Password { get; set; } public Contact Contact { get; set; } } public class Contact { public string Address { get; set; } public int PhoneNumber { get; set; } } ``` -------------------------------- ### Inject and Use GridifyMapper with Queryable in C# Source: https://alirezanet.github.io/Gridify/guide/dependency-injection This C# controller example shows how to inject `IGridifyMapper` into a controller. It then utilizes the `Gridify` extension method on an `IQueryable` to apply the provided query and custom mapper, returning a paginated result. This integrates Gridify's filtering and sorting directly into data retrieval logic. ```csharp public class WeatherForecastController : ControllerBase { private readonly IGridifyMapper _mapper; public WeatherForecastController(IGridifyMapper mapper) { _mapper = mapper; } [HttpGet(Name = "GetWeatherForecast")] public Paging Get([FromQuery] GridifyQuery query) { IQueryable result = GetWeatherForecasts(); // You can pass the mapper to the GridifyExtension return result.Gridify(query, _mapper); } } ``` -------------------------------- ### Create a Custom GridifyMapper with specific mappings Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Demonstrates creating a custom `GridifyMapper` for the `Person` entity. This example shows how to generate default mappings, explicitly remove a mapping for the 'Password' property, add custom mappings for 'address' and 'mobile' to nested 'Contact' properties, and enforce a lowercase transformation for 'userName' values. ```csharp var mapper = new GridifyMapper() .GenerateMappings() .RemoveMap(nameof(Person.Password)) .AddMap("address", p => p.Contact.Address) .AddMap("mobile", p => p.Contact.PhoneNumber) .AddMap("userName", p => p.UserName, v => v.ToLower()); ``` -------------------------------- ### Customized Elasticsearch Naming Convention Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch Shows how to customize the naming convention for Elasticsearch fields by setting GridifyGlobalConfiguration.CustomElasticsearchNamingAction. This example prefixes and suffixes field names with underscores. ```csharp GridifyGlobalConfiguration.CustomElasticsearchNamingAction = p => $"_{p}_"; await client.SearchAsync(s => s .Index("users") .ApplyFiltering("emailAddress = test@test.com")); ``` -------------------------------- ### Elasticsearch Query with Custom Mapping Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch Constructs an Elasticsearch query with custom field mappings using GridifyMapper. This example maps 'name', 'surname', 'age', and 'totalOrderPrice' to corresponding User properties and applies filtering, ordering, and paging. ```csharp var gq = new GridifyQuery() { Filter = "name=John, surname=Smith, age=30, totalOrderPrice=45", Page = 1, PageSize = 20, OrderBy = "Age" }; var mapper = new GridifyMapper() .AddMap("name", x => x.FirstName) .AddMap("surname", x => x.LastName) .AddMap("age", x => x.Age) .AddMap("totalOrderPrice", x => x.Order.TotalSum); var response = await client.SearchAsync(s => s .Index("users") .ApplyFilteringOrderingPaging(gq)); return response.Documents; ``` -------------------------------- ### API Controller Usage with GridifyQuery in C# Source: https://alirezanet.github.io/Gridify/v1 This example demonstrates how to use Gridify within an ASP.NET Web API controller to filter, sort, and paginate a list of 'Person' objects. It utilizes the GridifyQuery object, typically received as a query parameter, to configure the data retrieval process. The Gridify extension method is called on the DbContext's Persons DbSet. ```csharp // ApiController [Produces(typeof(Paging))] public IActionResult GetPersons([FromQuery] GridifyQuery gQuery) { // Gridify => Filter,Sort & Apply Paging // in short, Gridify returns data especially for data Grids. return myDbContext.Persons.Gridify(gQuery); } ``` -------------------------------- ### Get Expression Selector in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Retrieve the selector expression for a property using GetExpression, which can be utilized in LINQ queries with GridifyMapper. ```csharp Expression> selector = mapper.GetExpression(nameof(Person.Name)); ``` -------------------------------- ### Get Lambda Expression Selector in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Retrieve the selector expression as a LambdaExpression using GetLambdaExpression, suitable for various LINQ operations within GridifyMapper. ```csharp LambdaExpression selector = mapper.GetLambdaExpression(nameof(Person.Name)); ``` -------------------------------- ### Integrating Gridify with AutoMapper in C# Source: https://alirezanet.github.io/Gridify/v1 This C# code demonstrates how to combine Gridify's filtering capabilities with AutoMapper's `ProjectTo` for efficient data projection. It shows examples for filtering only, and for filtering, ordering, and paging, resulting in a `Paging` object containing projected DTOs. ```csharp //AutoMapper ProjectTo + Filtering Only, example var query = myDbContext.Persons.ApplyFiltering(gridifyQuery); var result = query.ProjectTo().ToList(); // AutoMapper ProjectTo + Filtering + Ordering + Paging, example QueryablePaging qp = myDbContext.Persons.GridifyQueryable(gridifyQuery); var result = new Paging () { Items = qp.Query.ProjectTo().ToList (), TotalItems = qp.TotalItems }; ``` -------------------------------- ### Custom GridifyTo Extension Method for AutoMapper Integration Source: https://alirezanet.github.io/Gridify/guide/autoMapper Provides a custom extension method `GridifyTo` that combines Gridify's data manipulation (filtering, ordering, paging) with AutoMapper's projection in a single step. This method requires AutoMapper and Gridify to be installed and offers a convenient way to perform these operations. ```csharp public static Paging GridifyTo( this IQueryable query, IMapper autoMapper, IGridifyQuery gridifyQuery, IGridifyMapper mapper = null) { var res = query.GridifyQueryable(gridifyQuery, mapper); return new Paging(res.Count, res.Query.ProjectTo(autoMapper.ConfigurationProvider).ToList()); } ``` -------------------------------- ### Custom Entity Mapping with GridifyMapper in C# Source: https://alirezanet.github.io/Gridify/v1 This C# example shows how to create a custom `GridifyMapper` for a `Person` entity, mapping DTO fields like 'address' and 'PhoneNumber' to nested properties within the entity (`Contact.Address` and `Contact.PhoneNumber`). It demonstrates generating default mappings and adding custom ones for complex scenarios. ```csharp // example Entities public class Person { public string FirstName {get;set;} public string LastName {get;set;} public Contact Contact {get;set;} } public class Contact { public string Address {get;set;} public int PhoneNumber {get;set;} } // example DTO public class PersonDTO { public string FirstName {get;set;} public string LastName {get;set;} public string Address {get;set;} public int PhoneNumber {get;set;} } //// GridifyMapper Usage example ------------- var customMappings = new GridifyMapper() // because FirstName and LastName is exists in both DTO and Entity classes we can Generate them .GenerateMappings() // add custom mappings .AddMap("address", q => q.Contact.Address ) .AddMap("PhoneNumber", q => q.Contact.PhoneNumber ); // as i mentioned before. usually we don't need create this object manually. var gQuery = new GridifyQuery() { Filter = "FirstName==John,Address=*st", IsSortAsc = true, SortBy = "PhoneNumber" }; // myRepository: could be entity framework context or any other collections var gridifiedData = myRepository.Persons.Gridify(gQuery, customMappings); ``` -------------------------------- ### Default Elasticsearch Naming Convention Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch Demonstrates the default behavior of Gridify.Elasticsearch where CLR property names are converted to camelCase for Elasticsearch field names. This example applies filtering to find users by email address. ```csharp await client.SearchAsync(s => s .Index("users") .ApplyFiltering("emailAddress = test@test.com")); ``` -------------------------------- ### Getting Distinct Field Expressions from SyntaxTree (C#) Source: https://alirezanet.github.io/Gridify/guide/syntax Illustrates how to retrieve all unique field expression syntax nodes, including the root and its descendants, from a SyntaxTree using the DistinctFieldExpressions method. This is useful for identifying all distinct fields mentioned in a filtering string. ```csharp var filterings = "name = Jack, arrayProp[8] > 10, dictProp[name] = John"; var fieldExpressions = SyntaxTree.Parse(filterings).Root.DistinctFieldExpressions(); ``` -------------------------------- ### Add Custom Field Mapping with Value Conversion in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Shows how to add a custom field mapping using `AddMap` where the third parameter is a value converter function. This example converts the input 'userName' value to lowercase before it's used for filtering. ```csharp mapper = mapper.AddMap("userName", p => p.UserName, value => value.ToLower()); ``` -------------------------------- ### Initialize GridifyQueryBuilder with Options Source: https://alirezanet.github.io/Gridify/guide/extensions/gridify-client Demonstrates how to create a new instance of GridifyQueryBuilder with optional configurations, such as allowing empty logical groups. ```typescript import { GridifyQueryBuilder } from "gridify-client"; const builder = new GridifyQueryBuilder({ allowEmptyGroups: true }); ``` -------------------------------- ### Configure GridifyQuery for Filtering, Ordering, and Paging Source: https://alirezanet.github.io/Gridify/guide/gridifyQuery Demonstrates how to instantiate and configure a GridifyQuery object with filter, page, page size, and order by properties. This query can then be applied to data repositories for efficient data manipulation. ```csharp var gq = new GridifyQuery() { Filter = "FirstName=John", Page = 1, PageSize = 20, OrderBy = "Age" }; // Apply Filter, Sort and Paging Paging result = personsRepo.Gridify(gq); ``` -------------------------------- ### Adding Gridify.EntityFramework Package Source: https://alirezanet.github.io/Gridify/v1 This shell command shows how to add the `Gridify.EntityFramework` NuGet package to your .NET project. This package provides asynchronous extensions for Entity Framework Core integration, including `GridifyAsync` and `GridifyQueryableAsync` methods. ```shell dotnet add package Gridify.EntityFramework ``` -------------------------------- ### Apply Ordering with Gridify in C# Source: https://alirezanet.github.io/Gridify/guide/ordering Demonstrates how to apply single and multiple ordering criteria (ascending and descending) using the `ApplyOrdering` method in C#. It assumes default ascending order if not specified. ```csharp var x = personsRepo.ApplyOrdering("Id"); // default ascending its equal to "Id asc" var x = personsRepo.ApplyOrdering("Id desc"); // use descending ordering // multiple orderings example var x = personsRepo.ApplyOrdering("Id desc, FirstName asc, LastName"); ``` -------------------------------- ### Basic User Retrieval in ASP.NET API Controller Source: https://alirezanet.github.io/Gridify/example/api-controller This C# code snippet shows a basic ASP.NET API controller action that returns a list of users from a data context. It serves as a baseline before applying Gridify for enhanced data handling. ```csharp //UserController // ... public IEnumerable GetUsers() { // context can be Entity Framework, a repository, or whatever. return context.Users.ToList(); } ``` -------------------------------- ### GridifyQuery Ordering in C# Source: https://alirezanet.github.io/Gridify/guide/ordering Shows how to specify ordering directly within a `GridifyQuery` object in C#. This includes setting single or multiple fields for ordering, with support for ascending and descending orders. ```csharp var gq = new GridifyQuery() { OrderBy = "Id" }; // default ascending its equal to "Id asc" var gq = new GridifyQuery() { OrderBy = "Id desc" }; // use descending ordering // multiple orderings example var gq = new GridifyQuery() { OrderBy = "Id desc, FirstName asc, LastName" }; ``` -------------------------------- ### Applying Gridify for Filtering, Sorting, and Pagination in ASP.NET Source: https://alirezanet.github.io/Gridify/example/api-controller This C# code snippet demonstrates how to use the Gridify library within an ASP.NET API controller to apply filtering, sorting, and pagination. It takes a GridifyQuery object from the request and returns a Paging object, simplifying data retrieval. ```csharp public Paging GetUsers([FromQuery] GridifyQuery query) { return context.Users.Gridify(query); } ``` -------------------------------- ### QueryBuilder Ordering in C# Source: https://alirezanet.github.io/Gridify/guide/ordering Illustrates using the `QueryBuilder` class in C# to add ordering criteria. It supports adding single or multiple ordering rules, including specifying ascending or descending order for each field. ```csharp var builder = new QueryBuilder(); // asc - desc builder.AddOrderBy("Id"); // default ascending its equal to "Id asc" builder.AddOrderBy("Id desc"); // use descending ordering // multiple orderings example builder.AddOrderBy("Id desc, FirstName asc, LastName"); ``` -------------------------------- ### Apply Ordering and Paging with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Applies ordering and paging simultaneously to an IQueryable collection or DbSet. This method takes an IGridifyQuery object, simplifying sorted and paginated data retrieval. ```csharp // Example assuming GridifyQuery object is created elsewhere // var gridifyQuery = new GridifyQuery { Order = "name", Page = 2, PageSize = 10 }; // var query = personsRepo.ApplyOrderingAndPaging(gridifyQuery); ``` -------------------------------- ### Define Gridify Mapping Profile in C# Source: https://alirezanet.github.io/Gridify/guide/dependency-injection This C# code defines a custom mapping profile for `WeatherForecast` by inheriting from `GridifyMapper`. It configures specific field mappings (e.g., 'summary' to `q.Summary`) and customizes mapper behavior like case sensitivity and null search handling. This class serves as a blueprint for Gridify's data transformation. ```csharp public class WeatherForecastGridifyMapper : GridifyMapper { public WeatherForecastGridifyMapper() { // Define your mappings here AddMap("summary", q => q.Summary); AddMap("temp", q => q.TemperatureC); // optionally you can customize the configuration for each mapper Configuration.CaseSensitive = false; Configuration.AllowNullSearch = true; Configuration.IgnoreNotMappedFields = true; } } ``` -------------------------------- ### Configure GridifyMapper with Custom Configuration Object Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Demonstrates initializing a `GridifyMapper` with a custom `GridifyMapperConfiguration` object. This allows setting properties like `CaseSensitive`, `AllowNullSearch`, and `IgnoreNotMappedFields` to customize the mapper's behavior. ```csharp var mapperConfig = new GridifyMapperConfiguration() { CaseSensitive = false, AllowNullSearch = true, IgnoreNotMappedFields = false }; var mapper = new GridifyMapper(mapperConfig); ``` -------------------------------- ### Initialize GridifyMapper with Default Mappings (Constructor) Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Demonstrates alternative ways to initialize a `GridifyMapper` with default mappings using the constructor. Passing `true` to the constructor generates top-level public property mappings without considering nesting depth. An optional second parameter can specify the maximum nesting depth. ```csharp var mapper = new GridifyMapper(true); var mapperWithDepth = new GridifyMapper(true, 2); ``` -------------------------------- ### Apply Paging to IQueryable with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Applies paging to an IQueryable collection or DbSet by specifying the page number and page size. This method translates directly to LINQ's Skip and Take methods for efficient data subset retrieval. ```csharp var query = personsRepo.ApplyPaging(3, 20); ``` -------------------------------- ### All-in-One Gridify Method for Paged Results Source: https://alirezanet.github.io/Gridify/guide/extensions An optimized, all-in-one method that accepts an IGridifyQuery and applies filtering, ordering, and paging. It returns a Paging object, designed for seamless integration with grid components. ```csharp // Example assuming GridifyQuery object is created elsewhere // var gridifyQuery = new GridifyQuery { Filter = "status = Active", Order = "date desc", Page = 1, PageSize = 15 }; // var pagedData = personsRepo.Gridify(gridifyQuery); ``` -------------------------------- ### Apply Filtering, Ordering, and Paging with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Applies filtering, ordering, and paging in one step to an IQueryable collection or DbSet. This method accepts an IGridifyQuery object for comprehensive query configuration. ```csharp // Example assuming GridifyQuery object is created elsewhere // var gridifyQuery = new GridifyQuery { Filter = "age > 30", Order = "name desc", Page = 1, PageSize = 25 }; // var query = personsRepo.ApplyFilteringOrderingPaging(gridifyQuery); ``` -------------------------------- ### Directly Parsing Filtering Strings (C#) Source: https://alirezanet.github.io/Gridify/guide/syntax Demonstrates the direct parsing of a filtering string into a collection of filtering objects using the ParseFilterings method. It shows how to iterate through the parsed filterings and access properties like MemberName. ```csharp var filterings = SyntaxTree.ParseFilterings("name = Jack, arrayProp[8] > 10, dictProp[name] = John"); foreach (var filtering in filterings) { Console.WriteLine(filtering.MemberName); } // name // arrayProp // dictProp ``` -------------------------------- ### Register Gridify Mappers with DI in C# Source: https://alirezanet.github.io/Gridify/guide/dependency-injection This C# code demonstrates how to register all Gridify mapping profiles within an assembly into the Dependency Injection container. It uses the `AddGridifyMappers` extension method on `IServiceCollection`, specifying the assembly to scan (e.g., `typeof(Program).Assembly`). This enables automatic discovery and registration of your custom mappers. ```csharp using Gridify; // Make sure to include the necessary namespace // ... public void ConfigureServices(IServiceCollection services) { // Other service registrations services.AddGridifyMappers(typeof(Program).Assembly); } ``` -------------------------------- ### Retrieving All Syntax Nodes from SyntaxTree (C#) Source: https://alirezanet.github.io/Gridify/guide/syntax Shows how to obtain all syntax nodes, including the current node and its descendants, from the root of a SyntaxTree using the Descendants method. It also demonstrates filtering these nodes by specific types like ExpressionSyntax, ValueExpressionSyntax, FieldExpressionSyntax, BinaryExpressionSyntax, and ParenthesizedExpressionSyntax. ```csharp var filterings = "name = Jack, arrayProp[8] > 10, dictProp[name] = John"; var syntaxNodes = SyntaxTree.Parse(filterings).Root.Descendants(); var expressions = syntaxNodes.OfType(); var valueExpressions = syntaxNodes.OfType(); var fieldExpressions = syntaxNodes.OfType(); var binaryExpressions = syntaxNodes.OfType(); var parenthesizedExpressions = syntaxNodes.OfType(); ``` -------------------------------- ### ApplyFiltering Extension Usage in C# Source: https://alirezanet.github.io/Gridify/v1 This C# snippet illustrates the use of the 'ApplyFiltering' extension method from Gridify. It shows how to filter a DbSet of 'Persons' based on a string condition 'name == John', which is equivalent to using a LINQ Where clause. ```csharp var query = myDbContext.Persons.ApplyFiltering("name == John"); // this is equal to : // myDbContext.Persons.Where(p => p.Name == "John"); ``` -------------------------------- ### Ordering Nullable Types with Gridify in C# Source: https://alirezanet.github.io/Gridify/guide/ordering Explains how to order by nullable types in C# using Gridify's special characters. The '?' character is used for ordering where the value has a value, and '!' is used for ordering where the value is null. This functionality is only supported for actual nullable types. ```csharp var x = personsRepo.ApplyOrdering("BirthDate?"); // Equivalent to personsRepo.OrderBy(p => p.BirthDate.HasValue) var x = personsRepo.ApplyOrdering("BirthDate!"); // Equivalent to personsRepo.OrderBy(p => !p.BirthDate.HasValue) ``` -------------------------------- ### Generate Default GridifyMapper Mappings Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Shows how to generate default mappings for a `GridifyMapper` using the `GenerateMappings()` method. This method automatically creates mappings for all public properties of the specified entity. ```csharp var mapper = new GridifyMapper() .GenerateMappings(); ``` -------------------------------- ### Enable Entity Framework Compatibility Layer for Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions/entityframework Enables the Entity Framework compatibility layer for Gridify by calling GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer(). This optimizes EF queries and enables parameterized queries. ```csharp GridifyGlobalConfiguration.EnableEntityFrameworkCompatibilityLayer(); ``` -------------------------------- ### Paging DTO Structure in Gridify Source: https://alirezanet.github.io/Gridify/example/api-controller This C# code defines the structure of the Paging DTO used by Gridify. It includes properties for the total count of records and an enumerable collection of data for the current page. ```csharp public int Count { get; set; } public IEnumerable Data { get; set; } ``` -------------------------------- ### Parsing Filterings into SyntaxTree Root (C#) Source: https://alirezanet.github.io/Gridify/guide/syntax Demonstrates how to parse a filtering string into a SyntaxTree and access its root node. The SyntaxTree is used internally by Gridify to create expression trees for filtering objects. ```csharp var root = SyntaxTree.Parse(filterings).Root; // ISyntaxNode ``` -------------------------------- ### Gridify Filtering: Logical Operators and Parentheses Source: https://alirezanet.github.io/Gridify/guide/filtering Illustrates how to combine multiple filter conditions using logical operators (AND, OR) and parentheses in Gridify to create complex queries. This allows for sophisticated data filtering based on multiple criteria. -------------------------------- ### Gridify Filtering: Conditional Operators Source: https://alirezanet.github.io/Gridify/guide/filtering Demonstrates the usage of various conditional operators in Gridify for filtering data based on field values. This includes equality, inequality, comparison, and pattern matching operators. ```csharp var x = personsRepo.ApplyFiltering("name="); ``` -------------------------------- ### Async GridifyTo Extension Method for AutoMapper Integration Source: https://alirezanet.github.io/Gridify/guide/autoMapper An asynchronous version of the `GridifyTo` extension method, designed for use with asynchronous data sources, such as those involving Entity Framework Core. This snippet requires the `Gridify.EntityFramework` package and facilitates non-blocking data manipulation and projection. ```csharp // only if you have Gridify.EntityFramework package installed. public static async Task> GridifyToAsync( this IQueryable query, IMapper autoMapper, IGridifyQuery gridifyQuery, IGridifyMapper mapper = null) { var res = await query.GridifyQueryableAsync(gridifyQuery, mapper); return new Paging(res.Count, await res.Query.ProjectTo(autoMapper.ConfigurationProvider).ToListAsync()); } ``` -------------------------------- ### Apply Ordering to IQueryable with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Applies ordering to an IQueryable collection or DbSet. This method simplifies column sorting with optional direction (ascending/descending) specified in a string. It's equivalent to using LINQ's OrderBy and ThenByDescending methods. ```csharp var query = personsRepo.ApplyOrdering("name, age desc"); ``` -------------------------------- ### Customize Elasticsearch Field Naming with C# Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch This C# code configures Gridify.Elasticsearch to use a custom naming action for document fields, prepending and appending underscores. It defines a `GridifyQuery` and applies it to an Elasticsearch search using the configured mapper. This requires the Gridify and Gridify.Elasticsearch packages. ```csharp Func? namingAction = p => $("_{p}_"); var mapper = new GridifyMapper(autoGenerateMappings: true) { Configuration = { CustomElasticsearchNamingAction = namingAction } }; var gq = new GridifyQuery() { Filter = "FirstName=John", Page = 1, PageSize = 20, OrderBy = "Age" }; var response = await client.SearchAsync(s => s .Index("users") .ApplyFilteringOrderingPaging(gq)); ``` -------------------------------- ### Elasticsearch Query with Gridify Without Pre-initialized Mapper Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch Generates an Elasticsearch query using Gridify filters, paging, and ordering without a pre-initialized mapper. It demonstrates applying paging, filtering, and ordering to a search request for 'User' documents. ```csharp var gq = new GridifyQuery() { Filter = "FirstName=John", Page = 1, PageSize = 20, OrderBy = "Age" }; var response = await client.SearchAsync(s => s .Index("users") .ApplyPaging(gq) .ApplyFiltering(gp) .ApplyOrdering(gp)); return response.Documents; ``` -------------------------------- ### Case-Sensitive GridifyMapper Configuration in C# Source: https://alirezanet.github.io/Gridify/v1 This C# snippet illustrates how to configure `GridifyMapper` to perform case-sensitive mappings. By passing `true` to the `GridifyMapper` constructor, the mapping process will distinguish between uppercase and lowercase characters in field names. ```csharp var customMappings = new GridifyMapper(true); // mapper is case-sensitive now. ``` -------------------------------- ### Apply Filtering and Ordering with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Combines filtering and ordering capabilities into a single operation on an IQueryable collection or DbSet. This method accepts an IGridifyQuery object, allowing for complex query definitions. ```csharp // Example assuming GridifyQuery object is created elsewhere // var gridifyQuery = new GridifyQuery { Filter = "name = John", Order = "age desc" }; // var query = personsRepo.ApplyFilteringAndOrdering(gridifyQuery); ``` -------------------------------- ### GridifyQueryable for Paginated Results with Count Source: https://alirezanet.github.io/Gridify/guide/extensions Similar to ApplyFilteringOrderingPaging, this method returns a QueryablePaging object. It includes an additional 'Count' property, which is the total number of items before paging, useful for front-end pagination controls. ```csharp // Example assuming GridifyQuery object is created elsewhere // var gridifyQuery = new GridifyQuery { Page = 1, PageSize = 10 }; // var pagedResults = personsRepo.GridifyQueryable(gridifyQuery); // int totalCount = pagedResults.Count; ``` -------------------------------- ### Enable EntityFramework Compatibility Layer in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Per-query setting to enable compatibility with Entity Framework for generated expressions. Useful when Gridify is used with EF queries. ```csharp var mapper = new GridifyMapper(q => q.EntityFrameworkCompatibilityLayer = true); ``` -------------------------------- ### AutoMapper ProjectTo with Gridify Filtering Source: https://alirezanet.github.io/Gridify/guide/autoMapper Demonstrates using AutoMapper's ProjectTo in conjunction with Gridify for filtering data. This snippet applies filtering before projecting to a DTO. It assumes the existence of a repository and Gridify's ApplyFiltering method. ```csharp var query = personRepo.ApplyFiltering(gridifyQuery); var result = query.ProjectTo().ToList(); ``` -------------------------------- ### Register Custom Operator in Gridify Source: https://alirezanet.github.io/Gridify/guide/gridifyGlobalConfiguration Demonstrates how to register a custom operator within Gridify's global configuration. This allows for extending Gridify's filtering and sorting capabilities with custom logic. Ensure the custom operator class implements the necessary interfaces. ```csharp GridifyGlobalConfiguration.CustomOperators.Register(); ``` -------------------------------- ### Enable Avoid Null Reference in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Per-query setting to prevent null reference exceptions during filtering operations, especially on collections. Similar to global configuration but applied individually. ```csharp var mapper = new GridifyMapper(q => q.AvoidNullReference = true); ``` -------------------------------- ### Map Indexable Properties (Dictionaries) in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Define mappings for filtering properties within dictionaries or navigation properties using key notation `[]` in GridifyMapper. Supports dynamic queries on specific dictionary entries. ```csharp var gm = new GridifyMapper() .AddMap("dictProp", (target, key) => target.MyDictionary[key]); var gm2 = new GridifyMapper() .AddMap("navProp", (target, key) => target.NavigationProperty.Where(n => n.Key == key).Select(n => n.Value)); var gq = new GridifyQuery { // Filters on the value associated with the 'name' key in a dictionary Filter = "dictProp[name] = John" }; ``` -------------------------------- ### Build Compiled Delegate with QueryBuilder in C# Source: https://alirezanet.github.io/Gridify/guide/compile Builds a compiled delegate directly from a QueryBuilder. This delegate can be invoked to filter collections, offering a high-performance solution for applying filters. Use this when you want a function that takes a collection and returns filtered results. ```csharp var func = new QueryBuilder() .AddCondition("name=John") .BuildCompiled(); var result = func(persons); ``` -------------------------------- ### Configure GridifyMapper for Case-Sensitive Mappings Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Shows how to enable case-sensitive mappings for `GridifyMapper` by passing a lambda expression to the constructor that sets the `CaseSensitive` property to `true`. By default, mappings are case-insensitive. ```csharp var mapper = new GridifyMapper(q => q.CaseSensitive = true); ``` -------------------------------- ### Gridify Filtering: Equivalent LINQ for Null/Empty Check Source: https://alirezanet.github.io/Gridify/guide/filtering Shows the equivalent LINQ query in C# for a Gridify filter that checks if a string property is null or empty. This is useful for understanding the underlying logic of the '=' operator when no value is provided. ```csharp var x = personsRepo.Where(p => p.Name is null || p.Name == string.Empty ); ``` -------------------------------- ### Validate GridifyQuery Filters and OrderBy Properties Source: https://alirezanet.github.io/Gridify/guide/gridifyQuery Shows how to use the IsValid extension method to check if the Filter and OrderBy properties of a GridifyQuery are valid for a given entity type or a custom mapper. It returns true if valid, false otherwise. ```csharp var gq = new GridifyQuery() { Filter = "name=John" , OrderBy = "Age" }; // true bool isValid = gq.IsValid(); ``` ```csharp var gq = new GridifyQuery() { Filter = "NonExist=John" , OrderBy = "Age" }; // false (NonExist is not a property of Person) bool isValid = gq.IsValid(); ``` ```csharp var gq = new GridifyQuery() { Filter = "@name=!" , OrderBy = "Age" }; // false (this is not a valid filter) bool isValid = gq.IsValid(); ``` ```csharp var mapper = new GridifyMapper() .AddMap("name", q => q.Name); var gq = new GridifyQuery() { Filter = "name=John" , OrderBy = "Age" }; // false (Age is not mapped) bool isValid = gq.IsValid(mapper); ``` -------------------------------- ### Register Custom Operators Globally - C# Source: https://alirezanet.github.io/Gridify/guide/filtering Demonstrates how to register custom Gridify operators, such as FreeTextOperator, RegexMatchOperator, and InOperator, globally using GridifyGlobalConfiguration.CustomOperators.Register(). ```csharp GridifyGlobalConfiguration.CustomOperators.Register(); GridifyGlobalConfiguration.CustomOperators.Register(); GridifyGlobalConfiguration.CustomOperators.Register(); ``` -------------------------------- ### Generate LINQ Filtering Expression from GridifyQuery Source: https://alirezanet.github.io/Gridify/guide/gridifyQuery Illustrates the use of the GetFilteringExpression extension method to create a lambda expression from the GridifyQuery.Filter property. This expression can be directly used with LINQ's Where method for efficient data filtering. ```csharp var gq = new GridifyQuery() { Filter = "name=John" }; Expression> expression = gq.GetFilteringExpression(); var result = personsRepo.Where(expression); ``` -------------------------------- ### Apply Filtering to IQueryable with Gridify Source: https://alirezanet.github.io/Gridify/guide/extensions Applies filtering to an IQueryable or DbSet using a raw string for dynamic filtering. This is an alternative to LINQ's Where clause, allowing for user-defined or dynamically generated filter expressions. Supports various filtering operators. ```csharp var query = personsRepo.ApplyFiltering("name = John"); ``` -------------------------------- ### Map Indexable Properties (Arrays) in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Define mappings for filtering properties within arrays or sub-collections using index notation `[]` in GridifyMapper. Supports dynamic queries on specific array elements. ```csharp var gm = new GridifyMapper() .AddMap("arrayProp", (target, index) => target.MyArray[index].Prop); var gq = new GridifyQuery { // Filters on the 8th element of an array property Filter = "arrayProp[8] > 10" }; ``` -------------------------------- ### Generic Overload for Non-String Dictionary Keys in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Utilize the generic overload of AddMap in GridifyMapper when dictionary keys are not strings, specifying the key type for correct mapping. ```csharp var gm = new GridifyMapper() .AddMap("dictProp", (target, key) => target.MyDictionary[key]); ``` -------------------------------- ### Compile GridifyQuery Expression in C# Source: https://alirezanet.github.io/Gridify/guide/compile Compiles a filtering expression from a GridifyQuery object for reuse. This method is suitable for scenarios where the expression needs to be applied multiple times without recompilation. It takes a GridifyQuery object and returns a compiled expression for filtering. ```csharp var gq = new GridifyQuery() { Filter = "name=John" }; var expression = gq.GetFilteringExpression(); var compiledExpression = expression.Compile(); var result = persons.Where(compiledExpression); ``` -------------------------------- ### Generate GridifyMapper Mappings with Nesting Depth Control Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Illustrates using `GenerateMappings(maxNestingDepth)` to control the depth of nested property mappings. The `maxNestingDepth` parameter specifies how many levels deep the mapper should look for properties in nested objects. A value of 0 means no nesting. ```csharp var mapper = new GridifyMapper() // Generates mappings for top-level properties and properties of nested classes up to 2 levels deep. .GenerateMappings(2); ``` -------------------------------- ### Gridify Filtering: Escaping Special Characters in C# Source: https://alirezanet.github.io/Gridify/guide/filtering Demonstrates how to escape special characters in C# using regular expressions for Gridify filter values. This ensures that characters like parentheses and commas are treated as literal values within the filter. ```csharp var value = "(test,test2)"; var esc = Regex.Replace(value, "([(),|\\]|\/i)", "\\$1" ); // esc = \(test\,test2\) ``` -------------------------------- ### Elasticsearch Query with Custom Field Names Source: https://alirezanet.github.io/Gridify/guide/extensions/elasticsearch This JSON represents an Elasticsearch search query that has been generated using the custom naming policy defined in the C# code. Notice how the field names ('_FirstName_' and '_Age_') reflect the custom naming action. This query filters by 'John', paginates from the first page with a size of 20, and sorts by age. ```json { "query": { "term": { "_FirstName_.keyword": { "value": "John" } } }, "from": 0, "size": 20, "sort": [{ "_Age_": { "order": "asc" } }] } ``` -------------------------------- ### Gridify Filtering: Case Insensitive Search Operator '/i' Source: https://alirezanet.github.io/Gridify/guide/filtering Explains how to perform case-insensitive searches in Gridify by appending the '/i' operator to the search value. This is useful for matching text regardless of character casing. ```csharp var x = personsRepo.ApplyFiltering("FirstName=John/i"); ``` -------------------------------- ### Configure Null Search Behavior in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Control whether Gridify allows searching on null values using the 'null' keyword. Setting AllowNullSearch to false disables this functionality. ```csharp var mapper = new GridifyMapper(q => q.AllowNullSearch = false); ``` -------------------------------- ### Compile QueryBuilder Expression in C# Source: https://alirezanet.github.io/Gridify/guide/compile Compiles a filtering expression built using the QueryBuilder class. This allows for efficient reuse of complex filter conditions across multiple operations. It's recommended for scenarios where you build filters programmatically and need to apply them repeatedly. ```csharp var compiledExpression = new QueryBuilder() .AddCondition("name=John") .BuildFilteringExpression() .Compile(); var result = persons.Where(compiledExpression); ``` -------------------------------- ### Filter Nested Collections with SelectMany in GridifyMapper Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Demonstrates filtering data based on properties within nested collections using LINQ Select and SelectMany methods with GridifyMapper. ```csharp var mapper = new GridifyMapper() .AddMap("prop1", l1 => l1.Level2List .SelectMany(l2 => l2.Level3List) .Select(l3 => l3.Property1)); // ... var query = level1List.ApplyFiltering("prop1 = 123", mapper); ``` -------------------------------- ### Gridify Filtering: Indexers for Arrays and Dictionaries (C#) Source: https://alirezanet.github.io/Gridify/guide/filtering Shows how to configure Gridify to filter properties that are indexable, such as elements within arrays or values in dictionaries. This involves defining mappings to access nested properties dynamically. ```csharp var gm = new GridifyMapper() .AddMap("arrayProp", (target, index) => target.MyArray[index].Prop) .AddMap("dictProp", (target, key) => target.MyDictionary[key]); var gq = new GridifyQuery { Filter = "arrayProp[8] > 10, dictProp[name] = John" }; ``` -------------------------------- ### Configure GridifyMapper to Ignore Unmapped Fields Source: https://alirezanet.github.io/Gridify/guide/gridifyMapper Demonstrates how to configure `GridifyMapper` to ignore fields that are not explicitly mapped. When `IgnoreNotMappedFields` is set to `true`, Gridify will not throw an exception if a query references a field name that has no corresponding mapping. ```csharp var mapper = new GridifyMapper(q => q.IgnoreNotMappedFields = true); ``` -------------------------------- ### Escape Special Characters for Filtering in C# Source: https://alirezanet.github.io/Gridify/v1 This C# code snippet demonstrates how to escape special filtering characters (`,`, `(`, `)`, `|`) using `Regex.Replace`. The escaped characters are prepended with a backslash to ensure they are treated as literal characters within Gridify filter values. ```csharp var value = "(test,test2)"; var esc = Regex.Replace(value, "([(),|])", "\\$1" ); // esc = \(test\,test2\) ``` -------------------------------- ### Define FreeTextOperator for Entity Framework - C# Source: https://alirezanet.github.io/Gridify/guide/filtering Implements a custom Gridify operator for free text search using Entity Framework's EF.Functions.FreeText. It defines the operator symbol '#=' and handles the expression for filtering. ```csharp class FreeTextOperator : IGridifyOperator { public string GetOperator() => "#="; public Expression OperatorHandler() { return (prop, value) => EF.Functions.FreeText(prop, value.ToString()); } } ```