SearchBuilder 1.1.0

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

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 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 193 8/25/2025
1.0.0 115 8/15/2025

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.