FluentFilterSharp 1.1.0

dotnet add package FluentFilterSharp --version 1.1.0
                    
NuGet\Install-Package FluentFilterSharp -Version 1.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentFilterSharp" Version="1.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FluentFilterSharp" Version="1.1.0" />
                    
Directory.Packages.props
<PackageReference Include="FluentFilterSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FluentFilterSharp --version 1.1.0
                    
#r "nuget: FluentFilterSharp, 1.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FluentFilterSharp@1.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FluentFilterSharp&version=1.1.0
                    
Install as a Cake Addin
#tool nuget:?package=FluentFilterSharp&version=1.1.0
                    
Install as a Cake Tool

FilterSharp is a powerful library for applying filtering, sorting, pagination, and change requests to IQueryable data sources in an efficient and secure manner.

🚀 FilterSharp v1.0.9 Released!

Support ValueObject or Nested object

📦 Features

  • ✅ Filtering: Apply dynamic filters to your data queries.
  • 🔄 Sorting: Sort data with multiple criteria.
  • 📄 Pagination: Easily paginate large datasets.
  • ⚙️ Change Requests: Handle and apply change requests dynamically.
  • 🔒 Security: Manage query permissions with Fluent API and attribute-based configurations.
  • ✨ Select Support: Dynamically select specific fields to optimize your queries and reduce unnecessary data retrieval.

📥 Installation

Install the package via NuGet Package Manager:

Install-Package FluentFilterSharp 

⚡ Injecting FilterSharp

        serviceCollection.AddFilterSharp(options =>
        { 
            options.DefaultPageSize = 10;
        });

🔹 How to Use This

🔄 Extending FilterSharp with Custom Mappers

You can extend FilterSharp by creating custom mappers for specific types. For example, you can create a UserFilterSharpMapper to customize filtering and sorting for a User entity.

public class UserFilterSharpMapper : AbstractFilterSharpMapper<User>
{
    public override void Configuration(FilterSharpMapperBuilder<User> builder)
    {
        builder.OnField(x => x.Name)
            .FilterFieldName("FirstName")
            .AllowedOperators([FilterOperator.Equals,FilterOperator.InRange])
            .DisableSort();

        builder.AllowedSelects([nameof(User.Name), nameof(User.Age)]);
    }
}

OR

public sealed class User
{
    public int Id { get; private set; }

    [FilterSharp(FilterFieldName = "FirstName",AllowedOperators = [FilterOperator.Equals,FilterOperator.Contains])]
    public string Name { get; private set; } 


🔒 Security

FilterSharp integrates security features allowing you to manage query permissions through Fluent API and attribute-based configurations. This ensures your data queries are protected from unauthorized access.

🛠️ Usage

FilterSharp provides two main extension methods for applying queries to your data sources:

ApplyQueryWithDetailsAsync – Returns data with additional metadata (e.g., total record count). ApplyQueryAsResultAsync – Returns filtered data only, without additional metadata.

support selects ApplyQueryAsResultAsync

var data = await _dbContext.Users.ApplyQueryWithDetailsAsync(queryRequest); 
var data = await _dbContext.Users.ApplyQueryAsResultAsync(queryRequest);   //=> support selects

Sample post

POST /api/data-query HTTP/1.1
Host: your-api-url.com
Content-Type: application/json

{
  "filters": [
    {
      "field": "name",
      "operator": "contains",
      "value": "david"
    },
    {
      "field": "lastname",
      "operator": "equals",
      "value": "mrf"
    },
  ],
  "sorting": [
    {
      "filedName": "createdDate",
      "ascending": false
    }
  ],
  "pageNumber": 1,
  "pageSize": 10
}

Supported Filter Operators in FilterRequest In DataQueryRequest under the FilterRequest class, the following filter operators are supported for the Operator property:

contains: Check if the value contains the specified string. Example: Check if the string "Hello World" contains the word "World".

notContains: Check if the value does not contain the specified string. Example: Check if the string "Hello World" does not contain the word "Goodbye".

equals: Check if the value is equal to the specified value. Example: Check if the number 5 is equal to 5.

notEqual: Check if the value is not equal to the specified value. Example: Check if the number 5 is not equal to 10.

lessThan: Check if the value is less than the specified value. Example: Check if the number 3 is less than 5.

lessThanOrEqual: Check if the value is less than or equal to the specified value. Example: Check if the number 5 is less than or equal to 5.

greaterThan: Check if the value is greater than the specified value. Example: Check if the number 7 is greater than 5.

greaterThanOrEqual: Check if the value is greater than or equal to the specified value. Example: Check if the number 6 is greater than or equal to 5.

blank: Check if the value is blank (null or empty). Example: Check if a field in the database is blank.

notBlank: Check if the value is not blank. Example: Check if a field in the database is not blank.

inRange: Check if the value is within a specified range. Example: Check if the number 7 is within the range of 5 to 10. For example:

startWith: Check if the value starts with the specified string. Example: Check if the string "Hello World" starts with the word "Hello".

Nested Filters Support: Nested Filters: FilterSharp also supports nested filters, which allow you to build complex queries by combining multiple filter conditions.

Logical Operators: The Logic property in FilterRequest determines how the conditions are combined. By default, it is set to AND, meaning all conditions must be true. However, you can override this in your request by setting it to OR.

AND: All conditions must be true. OR: Any one of the conditions must be true. These operators and logical combinations allow you to create dynamic and flexible queries for your data sources.


Product 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.  net9.0 was computed.  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.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
1.1.0 207 2/21/2025
1.0.9 150 1/11/2025
1.0.8 184 1/5/2025
1.0.7 169 1/5/2025
1.0.6 169 12/23/2024
1.0.5 169 12/22/2024
1.0.4 173 12/17/2024
1.0.3 176 12/17/2024
1.0.2 167 12/17/2024
1.0.1 168 12/17/2024
1.0.0 181 12/17/2024