# EF split query lab

Companion to [EF 11 Drops a Redundant Join From Split Queries](https://milanjovanovic.tech/blog/ef-core-11-split-query-redundant-join).

One benchmark project builds the same queries against EF Core 10 on .NET 10 and EF Core 11 on .NET 11.
You can dump the SQL each version sends for a split query and benchmark both against the same PostgreSQL 18 database.

## What you need

- Docker
- The .NET 10 SDK and the .NET 11 SDK

## Run it

```sh
docker compose up -d --wait
cd Benchmarks
dotnet run -c Release -f net11.0 -- seed
dotnet run -c Release -f net10.0 -- dump-sql sql-ef10.txt
dotnet run -c Release -f net11.0 -- dump-sql sql-ef11.txt
dotnet run -c Release -f net11.0 -- --filter '*'
```

- `seed` recreates the schema and inserts 1,000 customers, 500 products, 20,000 orders with 5 lines and 1 to 2 payments each, and about 30,000 addresses, from a fixed random seed.
- `dump-sql` runs every query once and writes the SQL EF Core sent. The target framework picks the EF Core version.
- The last command runs four benchmarks on both runtimes with BenchmarkDotNet. It takes several minutes.

`docker compose down -v` removes the container and its data.

## What is here

- `docker-compose.yml`: PostgreSQL 18 on `127.0.0.1:5438`.
- `src/Model.cs` and `src/AppDbContext.cs`: `Order` with a required `Customer` and `ShippingAddress`, an optional `BillingAddress` and `Carrier`, and the `Lines` and `Payments` collections.
- `src/Queries.cs`: the paged query and the date-range query, each with one reference and with four.
- `src/Seeder.cs` and `src/SqlDump.cs`: the data and the SQL dump.
- `Benchmarks/`: the project file with one EF Core package per target framework, the two jobs, and the four benchmarks.
- `output/`: my SQL dumps for both versions and my BenchmarkDotNet results.

## What to compare

- `output/sql-ef10.txt` and `output/sql-ef11.txt` are my dumps. Your statements should match them, the timestamps will not.
- `output/benchmarkdotnet.md` is my run. Your timings will differ, the ratios between EF Core 10 and EF Core 11 should be close.
