SearchBuilder 1.1.0
dotnet add package SearchBuilder --version 1.1.0
NuGet\Install-Package SearchBuilder -Version 1.1.0
<PackageReference Include="SearchBuilder" Version="1.1.0" />
<PackageVersion Include="SearchBuilder" Version="1.1.0" />
<PackageReference Include="SearchBuilder" />
paket add SearchBuilder --version 1.1.0
#r "nuget: SearchBuilder, 1.1.0"
#:package SearchBuilder@1.1.0
#addin nuget:?package=SearchBuilder&version=1.1.0
#tool nuget:?package=SearchBuilder&version=1.1.0
Search Builder — User Guide
1. Introduction
Search Builder
helps create dynamic filtering conditions for LINQ through a class that defines searchable fields.
You only need to declare properties and decorate them with [FieldMap]
specifying:
- Column name(s) in the database.
- Condition type (
KindField
). - Comparison operator (
Operation
).
The system will automatically generate an expression (Expression
) to pass into .Where(...)
when querying with EF Core.
2. Defining the Search Class
Example: SearchNhapKho
public class SearchNhapKho : PaginatedSortBaseRequest
{
[FieldMap("Ma,Kho.Ten", KindField.Search, Operation.Contains)]
public string? KeySearch { get; set; }
[FieldMap("Kho.Ten", KindField.Search, Operation.Contains)]
public string? TuKhoa { get; set; }
[FieldMap("Ma", KindField.Filter, Operation.EqualTo)]
public string? Ma { get; set; }
[FieldMap("Id", KindField.Filter, Operation.EqualTo)]
public int? Id { get; set; }
[FieldMap("SoLuong", KindField.Filter, Operation.GreaterThan)]
public int? SoLuongMin { get; set; }
[FieldMap("SoLuong", KindField.Filter, Operation.LessThan)]
public int? SoLuongMax { get; set; }
[FieldMap("NgayNhap", KindField.Filter, Operation.Between)]
public Range<DateTime?>? NgayNhapTuDen { get; set; }
[FieldMap("TrangThai", KindField.Filter, Operation.In)]
public List<int>? TrangThaiList { get; set; }
}
3. Usage in the Search Method
using SearchBuilder.Extensions;
-------------
var predicate = DynamicSearch.Build<NhapKho, SearchNhapKho>(search);
var query= _context.NhapKhos
.Include(x => x.Kho)
.Where(predicate)
.Select(t =>
new
{
Id = t.Id,
Ma = t.Ma,
TenKho = t.Kho.Ten
});
var result = await query.SortingAndPagingAsync(search);
4. Sample JSON Request
{
"sortBy": "name",
"isDescending": true,
"pageNumber": 1,
"pageSize": 10,
"keySearch": "string",
"tuKhoa": "string",
"ma": "string",
"id": 0,
"soLuongMin": 0,
"soLuongMax": 0,
"ngayNhapTuDen": {
"from": "2025-08-25T15:04:36.904Z",
"to": "2025-08-25T15:04:36.904Z"
},
"trangThaiList": [
0
]
}
💡 Notes
KindField.Search
→ Conditions are joined using OR.KindField.Filter
→ Conditions are joined using AND.Operation
→ Defines the comparison logic.
5. Reference
5.1. Range<T>
Property | Description |
---|---|
From |
Start value |
To |
End value |
5.2. KindField
— Relation Between Conditions
Value | LINQ Relation |
---|---|
Search |
OR |
Filter |
AND |
5.3. Operation
— Supported Comparison Operators
Name | Description | Notes |
---|---|---|
Contains |
Similar to .Contains() in LINQ |
|
EqualTo |
Equivalent to == |
|
StartsWith |
Similar to .StartsWith() |
|
EndsWith |
Similar to .EndsWith() |
|
GreaterThan |
> |
|
LessThan |
< |
|
GreaterThanOrEqual |
>= |
|
LessThanOrEqual |
<= |
|
In |
Value exists in list | Type must be List<T> |
Between |
Value is within range | Type must be Range<T> |
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
- Microsoft.EntityFrameworkCore (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
v1.0.0 - Initial release: supports [FieldMap] mapping, condition type (KindField),
and comparison operator (Operation) to automatically generate dynamic LINQ expressions.
v1.1.0 - Added sorting support for building dynamic order conditions alongside filtering.