NHQueryBuilder 1.0.0

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

NHQueryBuilder

NHQueryBuilder is a fluent, strongly-typed query builder for NHibernate that simplifies building complex queries in .NET.
It provides a modern, expressive API for filtering, ordering, projections, pagination, and more — all type-safe and fully integrated with NHibernate.


Key Features

  • Fluent API for Query Construction - Chain readable, type-safe methods.
  • Comprehensive Condition Support - Equal, NotEqual, IsIn, Between, Like, IsNull, GreaterThan, LessThan, etc.
  • Ordering & Pagination - OrderByAscending, OrderByDescending, Skip, Take.
  • Projections (Select) - Fetch only specific fields or map to DTOs.
  • Joins (Fetch) - Eagerly load related entities.
  • Count Queries - Get total record counts for conditions.
  • Integrated with NHibernate - Works seamlessly with ISession.
  • Extensible Design - Easily add new SQL functions or logic.

Getting Started

Define Entities

public class Author
{
    public virtual int Key { get; set; }
    public virtual string Name { get; set; }
    public virtual string Country { get; set; }
    public virtual string Nationality { get; set; }
    public virtual IList<Book> Books { get; set; }
}

public class Book
{
    public virtual int Key { get; set; }
    public virtual string Title { get; set; }
    public virtual Author Author { get; set; }
}

Build a Query

var cond = new FluentConditions<Author>()
    .Equal(x => x.Country, "India")
    .IsIn(x => x.Nationality, new[] { "American", "Indian", "Canadian" })
    .IsNotNull(x => x.Name)
    .OrderByAscending(x => x.Name)
    .Skip(10)
    .Take(10);

var authors = session.GetList(cond);

Select Only What You Need

cond.Select(x => new { x.Key, x.Name });
var results = session.GetProjectedList(cond);

Use transformer to map the results

cond.Select(x => new { x.Key, x.Name, x.Email });
var books = cs.GetProjectedList<Author, SimpleResult>(cond);

// Another way
FluentConditions<Book> conditions = new FluentConditions<Book>();
conditions.GreaterThan(x => x.Key, 10);
conditions.Select(x => x.Author);
var books = session.GetProjectedList<Book, Author>(conditions);

Use OR Conditions

cond.Equal(x => x.Country, "India").OR.Equal(x => x.Country, "Belgium");

Supported Methods

Category Methods
Comparison Equal, NotEqual, Between, GreaterThan, LessThan, etc.
Null Checks IsNull, IsNotNull
Membership IsIn, NotIn
String Like, NotLike
Projection Select
Joins Fetch
Ordering OrderByAscending, OrderByDescending
Pagination Skip, Take
Logical AND, OR

Unit Tests & Examples

NHQueryBuilder includes NUnit-based tests and example projects demonstrating:

  • Building dynamic conditions
  • Combining multiple joins
  • Executing projections
  • Applying pagination and sorting

See NHQueryBuilder.Example and NHQueryBuilder.UnitTest projects in the GitHub repository.


Community & Support

We'd love to hear your thoughts and feedback!

If you find this project useful, please star the repository to show your support!


License

This project is licensed under the MIT License. See the LICENSE file for details.


Acknowledgements

Built for the NHibernate community - simplifying advanced queries, one fluent line at a time.


NuGet Metadata

Metadata Value
Authors Prahsant Desai
Project URL https://github.com/pdesai84/NHQueryBuilder
License MIT
Tags NHibernate, QueryBuilder, Fluent, ORM, SQL, LINQ, C#, .NET
Repository Type GitHub
Repository URL https://github.com/pdesai84/NHQueryBuilder.git

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.0.0 198 11/7/2025