TranMinhSang.DynamicQueryExtension.EntityFrameworkCore 1.0.5

dotnet add package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 1.0.5
                    
NuGet\Install-Package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore -Version 1.0.5
                    
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="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="1.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="1.0.5" />
                    
Directory.Packages.props
<PackageReference Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" />
                    
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 TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 1.0.5
                    
#r "nuget: TranMinhSang.DynamicQueryExtension.EntityFrameworkCore, 1.0.5"
                    
#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 TranMinhSang.DynamicQueryExtension.EntityFrameworkCore@1.0.5
                    
#: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=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=1.0.5
                    
Install as a Cake Addin
#tool nuget:?package=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=1.0.5
                    
Install as a Cake Tool

Dynamic Query Extension

Support

  • Search
  • Sort
  • Filter with LHS Bracket syntax
  • Pagination with offset pagination and Cursor Pagination

NOTE

⚠️ PostgreSQL unaccent requirement

If you are using PostgreSQL, you MUST enable the unaccent extension before running the application or applying migrations.

1 Enable unaccent in PostgreSQL (run first)

Run this SQL once per database:

CREATE EXTENSION IF NOT EXISTS unaccent;

2 After the extension is enabled, add the following code to your DbContext:

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.HasDbFunction(
        typeof(PostgresDbFunctionExtensions).GetMethod(
            nameof(PostgresDbFunctionExtensions.Unaccent)
        )!
    );
}

The Search and Filter methods accept a DbContextProvider enum.

PostgreSQL works out of the box, but for other databases you must select the appropriate provider.

Supported providers: PostgreSQL, MySQL, and SQL Server

How to use

The First parameter is the key word The Second one is The Specific fields that You wanna search The Third is how deep this could search.

Using Database isn't PostgreSql, Pass your DbContextProvider.


dbContext.User
    .Search("rose",["name"], 1)
    .ToListAsync();

Filter

To do filter in this template, we use LHS Brackets.

LHS is the way to encode operators is the use of square brackets [] on the key name.

For example

GET api/v1/users?filter[dayOfBirth][$gt]="1990-10-01"

This example indicates filtering out users whose birthdays are after 1990/10/01

All support operations:

Operator Description
$eq Equal
$eqi Equal (case-insensitive)
$ne Not equal
$nei Not equal (case-insensitive)
$in Included in an array
$notin Not included in an array
$lt Less than
$lte Less than or equal to
$gt Greater than
$gte Greater than or equal to
$between Is between
$notcontains Does not contain
$notcontainsi Does not contain (case-insensitive)
$contains Contains
$containsi Contains (case-insensitive)
$startswith Starts with
$endswith Ends with

Some Examples:

GET /api/v1/users?filter[gender][$in][0]=1&filter[gender][$in][1]=2
GET /api/v1/users?filter[gender][$between][0]=1&filter[gender][$between][1]=2
GET /api/v1/users?filter[firstName][$contains]=abc

$and and $or operator:

GET /api/v1/users/filter[$and][0][firstName][$containsi]="sa"&filter[$and][1][lastName][$eq]="Tran"
{
  "filter": {
    "$and": {
      "firstName": "sa",
      "lastName": "Tran"
    }
  }
}
GET /api/v1/users/filter[$or][0][$and][0][claims][claimValue][$eq]=admin&filter[$or][1][lastName][$eq]=Tran
{
    "filter": {
        "$or": {
            "$and":{
                "claims": {
                    "claimValue": "admin"
                }
            },
            "lastName": "Tran"
        }
    }
}

For more examples and get better understand, you can visit

https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication#filtering
https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication#complex-filtering
https://docs.strapi.io/dev-docs/api/rest/filters-locale-publication#deep-filtering

I designed filter input based on Strapi filter

Using Database isn't PostgreSql, Pass your DbContextProvider as parameter to Filter method.

public string[] GetFilterQueries(string query, string filterKey)
{
    string[] queryParams = query[1..].Split("&", StringSplitOptions.TrimEntries);
    return
    [
        .. queryParams.Where(param =>
            param.StartsWith(
                filterKey,
                StringComparison.OrdinalIgnoreCase
            )
        ),
    ];
}

var query = httpContext?.Request.QueryString.Value;
string[] stringQuery = GetFilterQueries(query, "Filter");

List<QueryResult> queries =
        [
            .. StringExtension.TransformStringQuery(stringQuery),
        ];
object filter = StringExtension.Parse(queries);
await dbContext.User.Filter(filter).ToListAsync();

Sort

This example sorts users by name descending, then by age ascending when names are equal.

await dbContext.User.sort("name:desc, age").ToListAsync();

Pagination

Offset

   await dbContext.User.ToPagedListAsync(1, 10);

Cursor

  • Before : The previous Cursor
  • After : The next cursor
  • Size : Size of page
  • Sort : User sort request
  • UniqueSort : the property that is unique to make the mechanism work property, the default is Id:asc
await dbContext.User.ToCursorPagedListAsync(request);
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 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.  net10.0 is compatible.  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 (1)

Showing the top 1 popular GitHub repositories that depend on TranMinhSang.DynamicQueryExtension.EntityFrameworkCore:

Repository Stars
minhsangdotcom/clean-architecture
Clean Architecture template for .NET 🚀
Version Downloads Last Updated
1.0.5 99 2/2/2026
1.0.4 93 2/1/2026
1.0.3 215 12/5/2025
1.0.2 416 12/5/2025
1.0.1 298 11/11/2025
1.0.0 296 11/11/2025
0.1.2 176 11/7/2025
0.1.1 258 8/13/2025
0.1.0 191 8/13/2025