Tutorials Entity Framework Core Tutorial
SQL Query Analysis for EF Core
SQL Query Analysis for EF Core: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.
On this page
Entity Framework Core Tutorial · Lesson 89 of 100
SQL Query Analysis for EF Core
Beginner ✓ → Intermediate ✓ → Advanced ✓ → Professional
Professional · 4 — Real projects · ~10 min · Module 9: Testing & Debugging
What is this?
SQL query analysis copies EF-generated SQL into SSMS or Azure Data Studio, reviews actual execution plans, missing indexes, and waits — closing the loop between LINQ and database.
Why should you care?
ShopNest category browse LINQ looks fine — DBA analysis shows scan on 2M rows because EF translated Contains unexpectedly.
See it live — copy this example
Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).
var sql = _context.Products
.Where(p => categoryIds.Contains(p.CategoryId))
.OrderBy(p => p.Name)
.ToQueryString();
// Paste sql into SSMS → Include Actual Execution Plan → F5
// Look for: Index Seek vs Scan, Key Lookup, Sort cost, Warnings
What happened?
- ToQueryString outputs parameterized SQL EF will run.
- SSMS plan reveals whether Contains became IN seek or table scan — guides index or LINQ rewrite.
Practice next
- Copy ToQueryString output to SSMS against staging data volume.
- Enable actual execution plan before running.
- Check missing index suggestions — validate with DBA not blindly.
- Compare plan before/after composite index on CategoryId+Name.
- Use SET STATISTICS IO ON in SSMS to compare logical reads.
Remember
ToQueryString bridges LINQ to SSMS. Execution plan shows seek vs scan. Analyze on realistic row counts.
ShopNest DBA pairing
Dev shares ToQueryString and plan screenshot for slow search — DBA adds filtered index.
Outcome: Logical reads drop 90%; no LINQ change required.
Interview prep for this lesson
Practice these questions aloud after reading—each links to a full structured answer.
Sign in to ask a question or upvote helpful answers.
No questions yet — be the first to ask!