KiwiQuery.EFCore 1.0.0

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

KiwiQuery

Assert the number of SQL queries EF Core executes in your integration tests. Catch N+1 problems before they hit production.

Tired of writing the same DbCommandInterceptor boilerplate in every project just to check if your endpoint makes too many queries? This is for you.

await using var guard = factory.TrackQueries<Program, AppDbContext>();
var client = guard.CreateClient();

await client.GetAsync("/api/orders");

guard.AssertCount(exact: 1);

Installation

dotnet add package KiwiQuery.EFCore

Requirements

  • .NET 5+
  • EF Core 5+
  • Microsoft.AspNetCore.Mvc.Testing

Why

N+1 is one of those bugs that never shows up in unit tests — only in production, under load, when it's already too late. Writing a custom interceptor to catch it in integration tests is doable but tedious, and every team ends up copy-pasting the same 50 lines.

KiwiQuery wraps that into a single method call.

Usage

public class OrderTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly WebApplicationFactory<Program> _factory;

    public OrderTests(WebApplicationFactory<Program> factory)
    {
        _factory = factory;
    }

    [Fact]
    public async Task GetOrders_ExecutesExactlyOneQuery()
    {
        await using var guard = _factory.TrackQueries<Program, AppDbContext>();
        var client = guard.CreateClient();

        await client.GetAsync("/api/orders");

        guard.AssertCount(exact: 1);
    }
}

Assertions

guard.AssertCount(exact: 1);              // exactly 1 query
guard.AssertAtMost(3);                    // no more than 3
guard.AssertAtLeast(1);                   // at least 1
guard.AssertCount(atLeast: 1, atMost: 3); // range
guard.AssertNoQueries();                  // nothing hit the DB

If you just want the number:

Console.WriteLine(guard.Count);

Multiple DbContext types

Target a specific one:

await using var guard = _factory.TrackQueries<Program, AppDbContext>();

Or let it find all of them:

await using var guard = _factory.TrackQueries<Program>();

Multiple requests

The counter accumulates — useful if you want to assert a budget across several calls:

await client.GetAsync("/api/orders");
await client.GetAsync("/api/products");

guard.AssertAtMost(2);

What gets counted

SELECT, INSERT, UPDATE, DELETE, WITH — anything that hits your actual data. PRAGMA, schema checks, connection setup are ignored. Seeding and EnsureCreated() on startup don't count either.

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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

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 135 4/12/2026