![]() |
VOOZH | about |
dotnet add package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 1.0.8
NuGet\Install-Package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore -Version 1.0.8
<PackageReference Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="1.0.8" />
<PackageVersion Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="1.0.8" />Directory.Packages.props
<PackageReference Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" />Project file
paket add TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 1.0.8
#r "nuget: TranMinhSang.DynamicQueryExtension.EntityFrameworkCore, 1.0.8"
#:package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore@1.0.8
#addin nuget:?package=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=1.0.8Install as a Cake Addin
#tool nuget:?package=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=1.0.8Install as a Cake Tool
unaccent requirementIf you are using PostgreSQL, you MUST enable the unaccent extension before running the application or applying migrations.
unaccent in PostgreSQL (run first)Run this SQL once per database:
CREATE EXTENSION IF NOT EXISTS unaccent;
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
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();
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();
This example sorts users by name descending, then by age ascending when names are equal.
await dbContext.User.sort("name:desc, age").ToListAsync();
Offset
await dbContext.User.ToPagedListAsync(1, 10);
Cursor
await dbContext.User.ToCursorPagedListAsync(request);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 net8.0 is compatible. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
This package is not used by any NuGet packages.
Showing the top 1 popular GitHub repositories that depend on TranMinhSang.DynamicQueryExtension.EntityFrameworkCore:
| Repository | Stars |
|---|---|
|
minhsangdotcom/clean-architecture
Clean Architecture template for .NET 🚀
|