TinyBlueWhale.EngineQuery.SqlServer 1.0.0-preview

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

TinyBlueWhale.EngineQuery

Provider-agnostic high-performance SQL query builder for .NET.

EngineQuery generates deterministic SQL for SQL Server, PostgreSQL and MySQL using strongly typed expressions, advanced SQL capabilities and provider-specific dialect compilation.

Built for real-world Dapper, CQRS and SQL-heavy enterprise applications.

NuGet Downloads License


Why EngineQuery?

EngineQuery was created to solve a common problem in modern .NET applications:

Generating maintainable, provider-specific and deterministic SQL without the overhead and limitations of a full ORM.

Most applications eventually reach scenarios where:

  • LINQ becomes difficult to maintain
  • ORM-generated SQL becomes unpredictable
  • Reporting queries become too complex
  • Provider-specific SQL behavior matters
  • Performance tuning becomes critical
  • Dapper requires excessive manual SQL maintenance

EngineQuery bridges the gap between handwritten SQL and full ORM abstractions.


Features

  • Strongly typed query builder
  • SQL Server support
  • PostgreSQL support
  • MySQL support
  • Provider-specific SQL dialect generation
  • Deterministic SQL output
  • Window functions
  • Recursive CTEs
  • EXISTS / NOT EXISTS
  • APPLY / LATERAL
  • CASE WHEN
  • GROUP BY / HAVING
  • Aggregate functions
  • Compound JOIN conditions
  • Scalar functions
  • Computed expressions
  • UNION / INTERSECT / EXCEPT
  • Fluent metadata
  • Attribute metadata
  • Entity Framework metadata integration
  • Dependency injection support
  • Multi-provider architecture
  • Minimal allocations
  • Lightweight infrastructure

Supported Frameworks

  • .NET 8
  • .NET 9

Installation

dotnet add package TinyBlueWhale.EngineQuery.DependencyInjection

Package Structure

Package Purpose
TinyBlueWhale.EngineQuery.DependencyInjection Plug-and-play setup
TinyBlueWhale.EngineQuery.Core Query builder core
TinyBlueWhale.EngineQuery.SqlServer SQL Server provider
TinyBlueWhale.EngineQuery.MySql MySQL provider
TinyBlueWhale.EngineQuery.PostgreSql PostgreSQL provider
TinyBlueWhale.EngineQuery.Metadata Metadata mapping
TinyBlueWhale.EngineQuery.Metadata.EntityFramework EF Core metadata integration
TinyBlueWhale.EngineQuery.Abstractions Shared contracts
TinyBlueWhale.EngineQuery.Sql SQL compilation infrastructure

Choosing Packages

Scenario Recommended Package
Plug-and-play setup DependencyInjection
Manual setup Core
SQL Server only SqlServer
PostgreSQL only PostgreSql
MySQL only MySql
EF Core metadata reuse Metadata.EntityFramework
Custom provider implementation Sql + Abstractions

Quick Start

Dependency Injection

services.AddEngineQuery(options =>
{
    options.Add(QueryEngineProvider.SqlServer, metadata =>
    {
        metadata.UseFluentMetadata(BuildMetadataResolver.Create);
    });
});

Building Queries

public sealed class UserReportService
{
    private readonly IQueryEngine _queryEngine;

    public UserReportService(IQueryEngine queryEngine)
    {
        _queryEngine = queryEngine;
    }

    public GeneratedSqlQuery Build()
    {
        return _queryEngine
            .From<User>(alias: "u")
            .Select<User>(user => new
            {
                user.Id,
                user.Email
            })
            .Where<User>(user => user.IsActive)
            .OrderBy<User>(user => user.Id)
            .Build();
    }
}

Generated SQL

SELECT [u].[Id],
       [u].[Email]
FROM [Users] AS [u]
WHERE [u].[IsActive] = 1
ORDER BY [u].[Id] ASC

Multi-Provider Setup

services.AddEngineQuery(options =>
{
    options.Add(QueryEngineProvider.SqlServer, metadata =>
    {
        metadata.UseFluentMetadata(BuildSqlServerMetadata.Create);
    });

    options.Add(QueryEngineProvider.MySql, metadata =>
    {
        metadata.UseAttributeMetadata();
    });

    options.Add(QueryEngineProvider.PostgreSql, metadata =>
    {
        metadata.UseFluentMetadata(BuildPostgreSqlMetadata.Create);
    });
});

Selecting Providers Dynamically

public sealed class ReportService
{
    private readonly IQueryEngineFactory _factory;

    public ReportService(IQueryEngineFactory factory)
    {
        _factory = factory;
    }

    public GeneratedSqlQuery Build()
    {
        var queryEngine = _factory.Create(QueryEngineProvider.SqlServer);

        return queryEngine
            .From<User>(alias: "u")
            .Build();
    }
}

Metadata Strategies

EngineQuery supports multiple metadata resolution strategies.


Fluent Metadata

registry.Entity<User>()
    .ToTable("Users")
    .Property(user => user.Id)
    .HasColumnName("UserId");

Attribute Metadata

[Table("Users")]
public sealed class User
{
    [Column("UserId")]
    public int Id { get; set; }
}

Entity Framework Metadata

services.AddEngineQuery(options =>
{
    options.Add(QueryEngineProvider.SqlServer, metadata =>
    {
        metadata.UseEntityFrameworkMetadata<ApplicationDbContext>();
    });
});

Advanced Features

Window Functions

queryBuilder
    .From<Order>(alias: "o")
    .SelectRowNumber(
        "RowNumber",
        window => window
            .PartitionBy<Order>(order => order.CustomerId)
            .OrderByDescending<Order>(order => order.CreatedAt))
    .Build();

Recursive Common Table Expressions

queryBuilder
    .WithRecursive<CategoryNode>(
        "CategoryTree",
        anchor => anchor,
        recursive => recursive)
    .Build();

EXISTS

queryBuilder
    .From<User>(alias: "u")
    .WhereExists<Order>(
        subquery => subquery
            .From<Order>(alias: "o")
            .Where<Order>(order => order.UserId == 1))
    .Build();

APPLY / LATERAL

queryBuilder
    .From<User>(alias: "u")
    .CrossApply<Order>(
        "orders",
        apply => apply
            .From<Order>(alias: "o"))
    .Build();

Aggregate Functions

queryBuilder
    .From<Order>(alias: "o")
    .SelectSum<Order>(
        order => order.Total,
        "TotalSales")
    .GroupBy<Order>(order => order.CustomerId)
    .Build();

CASE WHEN

queryBuilder
    .From<Order>(alias: "o")
    .SelectCase(
        "Status",
        builder => builder
            .When<Order>(order => order.Total > 1000, "VIP")
            .Else("Standard"))
    .Build();

Designed For

  • Dapper applications
  • CQRS read models
  • Reporting systems
  • High-performance APIs
  • SQL-heavy applications
  • Enterprise reporting
  • Legacy SQL migrations
  • Multi-provider architectures
  • Provider-specific SQL optimization

Not Intended For

EngineQuery is not an ORM.

It does not provide:

  • Change tracking
  • Lazy loading
  • Entity persistence
  • IQueryable providers
  • Automatic migrations
  • LINQ execution providers

Architecture

EngineQuery uses a provider-agnostic query compilation pipeline.

The architecture is composed of:

  • Query builders
  • Query definitions
  • SQL clause builders
  • SQL dialects
  • Provider capabilities
  • Metadata resolvers
  • Query compilers

This allows deterministic SQL generation while maintaining provider-specific behavior.


Benchmarks

Benchmarks are available in the repository benchmark project.

Current benchmark scenarios include:

  • Basic select queries
  • JOIN aggregation
  • EXISTS subqueries
  • Derived tables
  • Common table expressions
  • Window functions
  • Set operations

Samples

Sample applications are available in the repository:

  • Playground
  • Sample applications
  • Provider comparison validators
  • Benchmark project

Repository

https://github.com/TinyBlueWhaleDev/EngineQuery


License

MIT

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 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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on TinyBlueWhale.EngineQuery.SqlServer:

Package Downloads
TinyBlueWhale.EngineQuery.DependencyInjection

Dependency injection extensions for EngineQuery multi-provider SQL generation.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-preview 64 5/20/2026