QueryFlow 1.0.0

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

QueryFlow

A powerful and flexible query builder library for .NET that allows you to build database queries dynamically and translate them to different query languages.

Features

  • Type-safe query building with LINQ-like syntax
  • Dynamic query building with runtime field specification
  • Multiple database support (SQL, MongoDB, and more)
  • Fluent API for intuitive query construction
  • Conditional query building for dynamic filtering
  • Advanced operations: joins, pagination, ordering, grouping
  • Query translation to SQL, MongoDB, and other formats

Installation

dotnet add package QueryFlow

Quick Start

Basic Usage

using QueryFlow;

// Type-safe query building
var query = QueryFlow.From<Product>()
    .Where(p => p.Price > 100)
    .Where(p => p.Category == "Electronics")
    .OrderBy(p => p.Name)
    .Take(10);

// Apply to IQueryable
var results = query.ApplyTo(dbContext.Products).ToList();

// Or translate to SQL
string sql = query.ToSql();
// SELECT * FROM Product WHERE Price > 100 AND Category = 'Electronics' ORDER BY Name ASC LIMIT 10

Dynamic Query Building

// Build queries with runtime field names
var dynamicQuery = QueryFlow.From(typeof(Product))
    .Where("Price", 100, ComparisonOperator.GreaterThan)
    .Where("Category", "Electronics")
    .OrderBy("Name")
    .Paginate(page: 1, pageSize: 20);

// Convert to SQL
string sql = dynamicQuery.ToSql();

Conditional Filtering

var query = QueryFlow.From<Product>();

// Only add filter if condition is true
query.Where(userInput.MinPrice.HasValue, p => p.Price >= userInput.MinPrice.Value)
     .Where(!string.IsNullOrEmpty(userInput.Category), p => p.Category == userInput.Category)
     .Where(userInput.InStock, p => p.StockQuantity > 0);

Complex Queries

var query = QueryFlow.From<Order>()
    .Join<Customer>(o => o.CustomerId, c => c.Id)
    .Where(o => o.OrderDate >= DateTime.Now.AddDays(-30))
    .OrWhere(o => o.Priority == "High")
    .Select("Id", "OrderDate", "Total")
    .OrderBy(o => o.OrderDate)
    .ThenBy(o => o.Total)
    .Distinct()
    .Paginate(page: 2, pageSize: 50);

MongoDB Translation

var query = QueryFlow.From<Product>()
    .Where(p => p.Price > 100)
    .OrderByDescending(p => p.CreatedAt)
    .Take(10);

// Translate to MongoDB aggregation pipeline
var mongoPipeline = query.ToMongo();

Advanced Features

Multiple Comparison Operators

var query = QueryFlow.From(typeof(Product))
    .WhereIn("Category", "Electronics", "Books", "Toys")
    .WhereBetween("Price", 10, 100)
    .WhereLike("Name", "%phone%")
    .Where("Brand", "Apple", ComparisonOperator.NotEqual);

Combining Conditions

var query = QueryFlow.From<Product>()
    .Where(p => p.Category == "Electronics")
    .Where(p => p.Price > 100)
    .OrWhere(p => p.Featured == true);

Pagination Helpers

// Method 1: Using Skip and Take
var query = QueryFlow.From<Product>()
    .Skip(20)
    .Take(10);

// Method 2: Using Paginate
var query = QueryFlow.From<Product>()
    .Paginate(page: 3, pageSize: 10); // Automatically calculates skip/take

API Reference

QueryBuilder<T> Methods

  • Where(Expression<Func<T, bool>>) - Add a WHERE condition
  • Where(bool condition, Expression<Func<T, bool>>) - Conditional WHERE
  • OrWhere(Expression<Func<T, bool>>) - Add an OR condition
  • OrderBy<TKey>(Expression<Func<T, TKey>>) - Order ascending
  • OrderByDescending<TKey>(Expression<Func<T, TKey>>) - Order descending
  • Select(params string[]) - Select specific fields
  • Skip(int) - Skip records
  • Take(int) - Limit results
  • Paginate(int page, int pageSize) - Pagination helper
  • Distinct() - Select distinct records
  • Join<TOther>() - Join with another entity
  • ApplyTo(IQueryable<T>) - Apply to LINQ query
  • ToSql() - Convert to SQL string
  • ToMongo() - Convert to MongoDB pipeline

DynamicQueryBuilder Methods

  • Where(string field, object value, ComparisonOperator op) - Dynamic WHERE
  • OrWhere(string field, object value, ComparisonOperator op) - Dynamic OR
  • WhereIn(string field, params object[] values) - IN operator
  • WhereBetween(string field, object min, object max) - BETWEEN operator
  • WhereLike(string field, string pattern) - LIKE operator
  • OrderBy(string field, bool descending) - Dynamic ordering
  • Select(params string[] fields) - Select fields
  • ToSql() - Convert to SQL string

Use Cases

REST API Filtering

[HttpGet]
public IActionResult GetProducts([FromQuery] ProductFilter filter)
{
    var query = QueryFlow.From<Product>()
        .Where(filter.MinPrice.HasValue, p => p.Price >= filter.MinPrice.Value)
        .Where(!string.IsNullOrEmpty(filter.Category), p => p.Category == filter.Category)
        .OrderBy(filter.SortBy ?? "Name", filter.SortDescending)
        .Paginate(filter.Page, filter.PageSize);
    
    var results = query.ApplyTo(dbContext.Products).ToList();
    return Ok(results);
}

GraphQL Resolvers

public class ProductResolver
{
    public IQueryable<Product> GetProducts(ProductArgs args)
    {
        var query = QueryFlow.From<Product>();
        
        if (args.Where != null)
        {
            foreach (var condition in args.Where)
            {
                query.Where(condition.Field, condition.Value, condition.Operator);
            }
        }
        
        if (args.OrderBy != null)
        {
            query.OrderBy(args.OrderBy.Field, args.OrderBy.Descending);
        }
        
        return query.ApplyTo(dbContext.Products);
    }
}

Admin Panel Dynamic Grids

public class GridService
{
    public GridResult<T> GetGridData<T>(GridRequest request) where T : class
    {
        var query = QueryFlow.From<T>();
        
        // Apply filters
        foreach (var filter in request.Filters)
        {
            query.Where(filter.Field, filter.Value, filter.Operator);
        }
        
        // Apply sorting
        foreach (var sort in request.Sorts)
        {
            query.OrderBy(sort.Field, sort.Descending);
        }
        
        // Apply pagination
        query.Paginate(request.Page, request.PageSize);
        
        return new GridResult<T>
        {
            Data = query.ApplyTo(GetQueryable<T>()).ToList(),
            TotalCount = GetTotalCount<T>(request.Filters)
        };
    }
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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.
  • net9.0

    • No dependencies.

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 149 9/2/2025