KiwiQuery.EFCore
1.0.0
dotnet add package KiwiQuery.EFCore --version 1.0.0
NuGet\Install-Package KiwiQuery.EFCore -Version 1.0.0
<PackageReference Include="KiwiQuery.EFCore" Version="1.0.0" />
<PackageVersion Include="KiwiQuery.EFCore" Version="1.0.0" />
<PackageReference Include="KiwiQuery.EFCore" />
paket add KiwiQuery.EFCore --version 1.0.0
#r "nuget: KiwiQuery.EFCore, 1.0.0"
#:package KiwiQuery.EFCore@1.0.0
#addin nuget:?package=KiwiQuery.EFCore&version=1.0.0
#tool nuget:?package=KiwiQuery.EFCore&version=1.0.0
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 | Versions 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. |
-
net5.0
- Microsoft.AspNetCore.Mvc.Testing (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
-
net6.0
- Microsoft.AspNetCore.Mvc.Testing (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
-
net7.0
- Microsoft.AspNetCore.Mvc.Testing (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
-
net8.0
- Microsoft.AspNetCore.Mvc.Testing (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
-
net9.0
- Microsoft.AspNetCore.Mvc.Testing (>= 5.0.0)
- Microsoft.EntityFrameworkCore.Relational (>= 5.0.0)
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 |