TranMinhSang.DynamicQueryExtension.EntityFrameworkCore
0.1.1
dotnet add package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 0.1.1
NuGet\Install-Package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore -Version 0.1.1
<PackageReference Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="0.1.1" />
<PackageVersion Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" Version="0.1.1" />
<PackageReference Include="TranMinhSang.DynamicQueryExtension.EntityFrameworkCore" />
paket add TranMinhSang.DynamicQueryExtension.EntityFrameworkCore --version 0.1.1
#r "nuget: TranMinhSang.DynamicQueryExtension.EntityFrameworkCore, 0.1.1"
#:package TranMinhSang.DynamicQueryExtension.EntityFrameworkCore@0.1.1
#addin nuget:?package=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=0.1.1
#tool nuget:?package=TranMinhSang.DynamicQueryExtension.EntityFrameworkCore&version=0.1.1
Dynamic Query Extension
Support
- Search
- Sort
- Filter with LHS Bracket syntax
- Pagination with offset pagination and Cursor Pagination
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
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
'Cause I designed filter input based on Strapi filter
To know how to binding from LHS to Dynamic object you could see my Clean Architecture Project Project
This file help you to grab filter string query
This will help you how to binding from LHS to Dynamic object
var query = httpContext?.Request.QueryString.Value;
string[] stringQuery = ModelBindingExtension.GetFilterQueries(query);
List<QueryResult> queries =
[
.. StringExtension.TransformStringQuery(stringQuery),
];
object filter = StringExtension.Parse(queries);
await dbContext.User.Filter(filter).ToListAsync();
I'll Update full of them for the next version.
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 | Versions 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. |
-
net8.0
- minhsangdotcom.TheTemplate.SharedKernel (>= 1.0.12)
- Newtonsoft.Json (>= 13.0.4-beta1)
- Npgsql.EntityFrameworkCore.PostgreSQL (>= 8.0.11)
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 Solution Template is for .NET Core🚀.
|