[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-dotnet-optimizing-ef-core-queries":3,"mdc-29ewph-key":37,"related-repo-dotnet-optimizing-ef-core-queries":1493,"related-org-dotnet-optimizing-ef-core-queries":1601},{"slug":4,"name":4,"fn":5,"description":6,"org":7,"tags":11,"stars":25,"repoUrl":26,"updatedAt":27,"license":28,"forks":29,"topics":30,"repo":32,"sourceUrl":35,"mdContent":36},"optimizing-ef-core-queries","optimize Entity Framework Core database queries","Optimize Entity Framework Core queries by fixing N+1 problems, choosing correct tracking modes, using compiled queries, and avoiding common performance traps. Use when EF Core queries are slow, generating excessive SQL, or causing high database load.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},"dotnet",".NET (Microsoft)","https:\u002F\u002Fpexgzepcugksgbtrxkhf.supabase.co\u002Fstorage\u002Fv1\u002Fobject\u002Fpublic\u002Forg-logos\u002Fdotnet.png",[12,16,19,22],{"name":13,"slug":14,"type":15},"Performance","performance","tag",{"name":17,"slug":18,"type":15},".NET","net",{"name":20,"slug":21,"type":15},"Database","database",{"name":23,"slug":24,"type":15},"ORM","orm",4576,"https:\u002F\u002Fgithub.com\u002Fdotnet\u002Fskills","2026-07-12T08:24:12.534643","MIT",332,[31],"agent-skills",{"repoUrl":26,"stars":25,"forks":29,"topics":33,"description":34},[31],"Repository for skills to assist AI coding agents with .NET and C#","https:\u002F\u002Fgithub.com\u002Fdotnet\u002Fskills\u002Ftree\u002FHEAD\u002Fplugins\u002Fdotnet-data\u002Fskills\u002Foptimizing-ef-core-queries","---\nname: optimizing-ef-core-queries\ndescription: Optimize Entity Framework Core queries by fixing N+1 problems, choosing correct tracking modes, using compiled queries, and avoiding common performance traps. Use when EF Core queries are slow, generating excessive SQL, or causing high database load.\nlicense: MIT\n---\n\n# Optimizing EF Core Queries\n\n## When to Use\n\n- EF Core queries are slow or generating too many SQL statements\n- Database CPU\u002FIO is high due to ORM inefficiency\n- N+1 query patterns are detected in logs\n- Large result sets cause memory pressure\n\n## When Not to Use\n\n- The user is using Dapper or raw ADO.NET (not EF Core)\n- The performance issue is database-side (missing indexes, bad schema)\n- The user is building a new data access layer from scratch\n\n## Inputs\n\n| Input | Required | Description |\n|-------|----------|-------------|\n| Slow EF Core queries | Yes | The LINQ queries or DbContext usage to optimize |\n| SQL output or logs | No | EF Core generated SQL or query execution logs |\n\n## Workflow\n\n### Step 1: Enable query logging to see the actual SQL\n\n```csharp\n\u002F\u002F In Program.cs or DbContext configuration:\noptionsBuilder\n    .UseSqlServer(connectionString)\n    .LogTo(Console.WriteLine, LogLevel.Information)\n    .EnableSensitiveDataLogging()  \u002F\u002F shows parameter values (dev only!)\n    .EnableDetailedErrors();\n```\n\nOr use the `Microsoft.EntityFrameworkCore` log category:\n\n```json\n{\n  \"Logging\": {\n    \"LogLevel\": {\n      \"Microsoft.EntityFrameworkCore.Database.Command\": \"Information\"\n    }\n  }\n}\n```\n\n### Step 2: Fix N+1 query patterns\n\n**The #1 EF Core performance killer.** Happens when loading related entities in a loop.\n\n**Before (N+1 — 1 query for orders + N queries for items):**\n```csharp\nvar orders = await db.Orders.ToListAsync();\nforeach (var order in orders)\n{\n    \u002F\u002F Each access triggers a lazy-load query!\n    var items = order.Items.Count;\n}\n```\n\n**After (eager loading — 1 or 2 queries total):**\n```csharp\n\u002F\u002F Option 1: Include (JOIN)\nvar orders = await db.Orders\n    .Include(o => o.Items)\n    .ToListAsync();\n\n\u002F\u002F Option 2: Split query (separate SQL, avoids cartesian explosion)\nvar orders = await db.Orders\n    .Include(o => o.Items)\n    .AsSplitQuery()\n    .ToListAsync();\n\n\u002F\u002F Option 3: Explicit projection (best - only fetches needed columns)\nvar orderSummaries = await db.Orders\n    .Select(o => new OrderSummary\n    {\n        OrderId = o.Id,\n        Total = o.Items.Sum(i => i.Price),\n        ItemCount = o.Items.Count\n    })\n    .ToListAsync();\n```\n\n**When to use Split vs Single query:**\n\n| Scenario | Use |\n|----------|-----|\n| 1 level of Include | Single query (default) |\n| Multiple Includes (Cartesian risk) | `AsSplitQuery()` |\n| Include with large child collections | `AsSplitQuery()` |\n| Need transaction consistency | Single query |\n\n### Step 3: Use NoTracking for read-only queries\n\n**Change tracking overhead is significant.** Disable it when you don't need to update entities:\n\n```csharp\n\u002F\u002F Per-query\nvar products = await db.Products\n    .AsNoTracking()\n    .Where(p => p.IsActive)\n    .ToListAsync();\n\n\u002F\u002F Global default for read-heavy apps\nservices.AddDbContext\u003CAppDbContext>(options =>\n    options.UseSqlServer(connectionString)\n           .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));\n```\n\n**Use `AsNoTrackingWithIdentityResolution()` when the query returns duplicate entities to avoid duplicated objects in memory.**\n\n### Step 4: Use compiled queries for hot paths\n\n```csharp\n\u002F\u002F Define once as static\nprivate static readonly Func\u003CAppDbContext, int, Task\u003COrder?>> GetOrderById =\n    EF.CompileAsyncQuery((AppDbContext db, int id) =>\n        db.Orders\n            .Include(o => o.Items)\n            .FirstOrDefault(o => o.Id == id));\n\n\u002F\u002F Use repeatedly — skips query compilation overhead\nvar order = await GetOrderById(db, orderId);\n```\n\n### Step 5: Avoid common query traps\n\n| Trap | Problem | Fix |\n|------|---------|-----|\n| `ToList()` before `Where()` | Loads entire table into memory | Filter first: `.Where().ToList()` |\n| `Count()` to check existence | Scans all rows | Use `.Any()` instead |\n| `.Select()` after `.Include()` | Include is ignored with projection | Remove Include, use Select only |\n| `string.Contains()` in Where | May not translate, falls to client eval | Use `EF.Functions.Like()` for SQL LIKE |\n| Calling `.ToList()` inside `Select()` | Causes nested queries | Use projection with `Select` all the way |\n\n### Step 6: Use raw SQL or FromSql for complex queries\n\nWhen LINQ can't express it efficiently:\n\n```csharp\nvar results = await db.Orders\n    .FromSqlInterpolated($@\"\n        SELECT o.* FROM Orders o\n        INNER JOIN (\n            SELECT OrderId, SUM(Price) as Total\n            FROM OrderItems\n            GROUP BY OrderId\n            HAVING SUM(Price) > {minTotal}\n        ) t ON o.Id = t.OrderId\")\n    .AsNoTracking()\n    .ToListAsync();\n```\n\n## Validation\n\n- [ ] SQL logging shows expected number of queries (no N+1)\n- [ ] Read-only queries use `AsNoTracking()`\n- [ ] Hot-path queries use compiled queries\n- [ ] No client-side evaluation warnings in logs\n- [ ] Include\u002Fsplit strategy matches data shape\n\n## Common Pitfalls\n\n| Pitfall | Solution |\n|---------|----------|\n| Lazy loading silently creating N+1 | Remove `Microsoft.EntityFrameworkCore.Proxies` or disable lazy loading |\n| Global query filters forgotten in perf analysis | Check `HasQueryFilter` in model config; use `IgnoreQueryFilters()` if needed |\n| `DbContext` kept alive too long | DbContext should be scoped (per-request); don't cache it |\n| Batch updates fetching then saving | EF Core 7+: use `ExecuteUpdateAsync` \u002F `ExecuteDeleteAsync` for bulk operations |\n| String interpolation in `FromSqlRaw` | SQL injection risk — use `FromSqlInterpolated` (parameterized) |\n",{"data":38,"body":39},{"name":4,"description":6,"license":28},{"type":40,"children":41},"root",[42,50,57,82,88,106,112,181,187,194,262,276,412,418,429,437,490,498,674,682,763,769,779,864,880,886,964,970,1165,1171,1176,1269,1275,1334,1340,1487],{"type":43,"tag":44,"props":45,"children":46},"element","h1",{"id":4},[47],{"type":48,"value":49},"text","Optimizing EF Core Queries",{"type":43,"tag":51,"props":52,"children":54},"h2",{"id":53},"when-to-use",[55],{"type":48,"value":56},"When to Use",{"type":43,"tag":58,"props":59,"children":60},"ul",{},[61,67,72,77],{"type":43,"tag":62,"props":63,"children":64},"li",{},[65],{"type":48,"value":66},"EF Core queries are slow or generating too many SQL statements",{"type":43,"tag":62,"props":68,"children":69},{},[70],{"type":48,"value":71},"Database CPU\u002FIO is high due to ORM inefficiency",{"type":43,"tag":62,"props":73,"children":74},{},[75],{"type":48,"value":76},"N+1 query patterns are detected in logs",{"type":43,"tag":62,"props":78,"children":79},{},[80],{"type":48,"value":81},"Large result sets cause memory pressure",{"type":43,"tag":51,"props":83,"children":85},{"id":84},"when-not-to-use",[86],{"type":48,"value":87},"When Not to Use",{"type":43,"tag":58,"props":89,"children":90},{},[91,96,101],{"type":43,"tag":62,"props":92,"children":93},{},[94],{"type":48,"value":95},"The user is using Dapper or raw ADO.NET (not EF Core)",{"type":43,"tag":62,"props":97,"children":98},{},[99],{"type":48,"value":100},"The performance issue is database-side (missing indexes, bad schema)",{"type":43,"tag":62,"props":102,"children":103},{},[104],{"type":48,"value":105},"The user is building a new data access layer from scratch",{"type":43,"tag":51,"props":107,"children":109},{"id":108},"inputs",[110],{"type":48,"value":111},"Inputs",{"type":43,"tag":113,"props":114,"children":115},"table",{},[116,140],{"type":43,"tag":117,"props":118,"children":119},"thead",{},[120],{"type":43,"tag":121,"props":122,"children":123},"tr",{},[124,130,135],{"type":43,"tag":125,"props":126,"children":127},"th",{},[128],{"type":48,"value":129},"Input",{"type":43,"tag":125,"props":131,"children":132},{},[133],{"type":48,"value":134},"Required",{"type":43,"tag":125,"props":136,"children":137},{},[138],{"type":48,"value":139},"Description",{"type":43,"tag":141,"props":142,"children":143},"tbody",{},[144,163],{"type":43,"tag":121,"props":145,"children":146},{},[147,153,158],{"type":43,"tag":148,"props":149,"children":150},"td",{},[151],{"type":48,"value":152},"Slow EF Core queries",{"type":43,"tag":148,"props":154,"children":155},{},[156],{"type":48,"value":157},"Yes",{"type":43,"tag":148,"props":159,"children":160},{},[161],{"type":48,"value":162},"The LINQ queries or DbContext usage to optimize",{"type":43,"tag":121,"props":164,"children":165},{},[166,171,176],{"type":43,"tag":148,"props":167,"children":168},{},[169],{"type":48,"value":170},"SQL output or logs",{"type":43,"tag":148,"props":172,"children":173},{},[174],{"type":48,"value":175},"No",{"type":43,"tag":148,"props":177,"children":178},{},[179],{"type":48,"value":180},"EF Core generated SQL or query execution logs",{"type":43,"tag":51,"props":182,"children":184},{"id":183},"workflow",[185],{"type":48,"value":186},"Workflow",{"type":43,"tag":188,"props":189,"children":191},"h3",{"id":190},"step-1-enable-query-logging-to-see-the-actual-sql",[192],{"type":48,"value":193},"Step 1: Enable query logging to see the actual SQL",{"type":43,"tag":195,"props":196,"children":201},"pre",{"className":197,"code":198,"language":199,"meta":200,"style":200},"language-csharp shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F In Program.cs or DbContext configuration:\noptionsBuilder\n    .UseSqlServer(connectionString)\n    .LogTo(Console.WriteLine, LogLevel.Information)\n    .EnableSensitiveDataLogging()  \u002F\u002F shows parameter values (dev only!)\n    .EnableDetailedErrors();\n","csharp","",[202],{"type":43,"tag":203,"props":204,"children":205},"code",{"__ignoreMap":200},[206,217,226,235,244,253],{"type":43,"tag":207,"props":208,"children":211},"span",{"class":209,"line":210},"line",1,[212],{"type":43,"tag":207,"props":213,"children":214},{},[215],{"type":48,"value":216},"\u002F\u002F In Program.cs or DbContext configuration:\n",{"type":43,"tag":207,"props":218,"children":220},{"class":209,"line":219},2,[221],{"type":43,"tag":207,"props":222,"children":223},{},[224],{"type":48,"value":225},"optionsBuilder\n",{"type":43,"tag":207,"props":227,"children":229},{"class":209,"line":228},3,[230],{"type":43,"tag":207,"props":231,"children":232},{},[233],{"type":48,"value":234},"    .UseSqlServer(connectionString)\n",{"type":43,"tag":207,"props":236,"children":238},{"class":209,"line":237},4,[239],{"type":43,"tag":207,"props":240,"children":241},{},[242],{"type":48,"value":243},"    .LogTo(Console.WriteLine, LogLevel.Information)\n",{"type":43,"tag":207,"props":245,"children":247},{"class":209,"line":246},5,[248],{"type":43,"tag":207,"props":249,"children":250},{},[251],{"type":48,"value":252},"    .EnableSensitiveDataLogging()  \u002F\u002F shows parameter values (dev only!)\n",{"type":43,"tag":207,"props":254,"children":256},{"class":209,"line":255},6,[257],{"type":43,"tag":207,"props":258,"children":259},{},[260],{"type":48,"value":261},"    .EnableDetailedErrors();\n",{"type":43,"tag":263,"props":264,"children":265},"p",{},[266,268,274],{"type":48,"value":267},"Or use the ",{"type":43,"tag":203,"props":269,"children":271},{"className":270},[],[272],{"type":48,"value":273},"Microsoft.EntityFrameworkCore",{"type":48,"value":275}," log category:",{"type":43,"tag":195,"props":277,"children":281},{"className":278,"code":279,"language":280,"meta":200,"style":200},"language-json shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","{\n  \"Logging\": {\n    \"LogLevel\": {\n      \"Microsoft.EntityFrameworkCore.Database.Command\": \"Information\"\n    }\n  }\n}\n","json",[282],{"type":43,"tag":203,"props":283,"children":284},{"__ignoreMap":200},[285,294,323,349,387,395,403],{"type":43,"tag":207,"props":286,"children":287},{"class":209,"line":210},[288],{"type":43,"tag":207,"props":289,"children":291},{"style":290},"--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF",[292],{"type":48,"value":293},"{\n",{"type":43,"tag":207,"props":295,"children":296},{"class":209,"line":219},[297,302,308,313,318],{"type":43,"tag":207,"props":298,"children":299},{"style":290},[300],{"type":48,"value":301},"  \"",{"type":43,"tag":207,"props":303,"children":305},{"style":304},"--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA",[306],{"type":48,"value":307},"Logging",{"type":43,"tag":207,"props":309,"children":310},{"style":290},[311],{"type":48,"value":312},"\"",{"type":43,"tag":207,"props":314,"children":315},{"style":290},[316],{"type":48,"value":317},":",{"type":43,"tag":207,"props":319,"children":320},{"style":290},[321],{"type":48,"value":322}," {\n",{"type":43,"tag":207,"props":324,"children":325},{"class":209,"line":228},[326,331,337,341,345],{"type":43,"tag":207,"props":327,"children":328},{"style":290},[329],{"type":48,"value":330},"    \"",{"type":43,"tag":207,"props":332,"children":334},{"style":333},"--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B",[335],{"type":48,"value":336},"LogLevel",{"type":43,"tag":207,"props":338,"children":339},{"style":290},[340],{"type":48,"value":312},{"type":43,"tag":207,"props":342,"children":343},{"style":290},[344],{"type":48,"value":317},{"type":43,"tag":207,"props":346,"children":347},{"style":290},[348],{"type":48,"value":322},{"type":43,"tag":207,"props":350,"children":351},{"class":209,"line":237},[352,357,363,367,371,376,382],{"type":43,"tag":207,"props":353,"children":354},{"style":290},[355],{"type":48,"value":356},"      \"",{"type":43,"tag":207,"props":358,"children":360},{"style":359},"--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C",[361],{"type":48,"value":362},"Microsoft.EntityFrameworkCore.Database.Command",{"type":43,"tag":207,"props":364,"children":365},{"style":290},[366],{"type":48,"value":312},{"type":43,"tag":207,"props":368,"children":369},{"style":290},[370],{"type":48,"value":317},{"type":43,"tag":207,"props":372,"children":373},{"style":290},[374],{"type":48,"value":375}," \"",{"type":43,"tag":207,"props":377,"children":379},{"style":378},"--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D",[380],{"type":48,"value":381},"Information",{"type":43,"tag":207,"props":383,"children":384},{"style":290},[385],{"type":48,"value":386},"\"\n",{"type":43,"tag":207,"props":388,"children":389},{"class":209,"line":246},[390],{"type":43,"tag":207,"props":391,"children":392},{"style":290},[393],{"type":48,"value":394},"    }\n",{"type":43,"tag":207,"props":396,"children":397},{"class":209,"line":255},[398],{"type":43,"tag":207,"props":399,"children":400},{"style":290},[401],{"type":48,"value":402},"  }\n",{"type":43,"tag":207,"props":404,"children":406},{"class":209,"line":405},7,[407],{"type":43,"tag":207,"props":408,"children":409},{"style":290},[410],{"type":48,"value":411},"}\n",{"type":43,"tag":188,"props":413,"children":415},{"id":414},"step-2-fix-n1-query-patterns",[416],{"type":48,"value":417},"Step 2: Fix N+1 query patterns",{"type":43,"tag":263,"props":419,"children":420},{},[421,427],{"type":43,"tag":422,"props":423,"children":424},"strong",{},[425],{"type":48,"value":426},"The #1 EF Core performance killer.",{"type":48,"value":428}," Happens when loading related entities in a loop.",{"type":43,"tag":263,"props":430,"children":431},{},[432],{"type":43,"tag":422,"props":433,"children":434},{},[435],{"type":48,"value":436},"Before (N+1 — 1 query for orders + N queries for items):",{"type":43,"tag":195,"props":438,"children":440},{"className":197,"code":439,"language":199,"meta":200,"style":200},"var orders = await db.Orders.ToListAsync();\nforeach (var order in orders)\n{\n    \u002F\u002F Each access triggers a lazy-load query!\n    var items = order.Items.Count;\n}\n",[441],{"type":43,"tag":203,"props":442,"children":443},{"__ignoreMap":200},[444,452,460,467,475,483],{"type":43,"tag":207,"props":445,"children":446},{"class":209,"line":210},[447],{"type":43,"tag":207,"props":448,"children":449},{},[450],{"type":48,"value":451},"var orders = await db.Orders.ToListAsync();\n",{"type":43,"tag":207,"props":453,"children":454},{"class":209,"line":219},[455],{"type":43,"tag":207,"props":456,"children":457},{},[458],{"type":48,"value":459},"foreach (var order in orders)\n",{"type":43,"tag":207,"props":461,"children":462},{"class":209,"line":228},[463],{"type":43,"tag":207,"props":464,"children":465},{},[466],{"type":48,"value":293},{"type":43,"tag":207,"props":468,"children":469},{"class":209,"line":237},[470],{"type":43,"tag":207,"props":471,"children":472},{},[473],{"type":48,"value":474},"    \u002F\u002F Each access triggers a lazy-load query!\n",{"type":43,"tag":207,"props":476,"children":477},{"class":209,"line":246},[478],{"type":43,"tag":207,"props":479,"children":480},{},[481],{"type":48,"value":482},"    var items = order.Items.Count;\n",{"type":43,"tag":207,"props":484,"children":485},{"class":209,"line":255},[486],{"type":43,"tag":207,"props":487,"children":488},{},[489],{"type":48,"value":411},{"type":43,"tag":263,"props":491,"children":492},{},[493],{"type":43,"tag":422,"props":494,"children":495},{},[496],{"type":48,"value":497},"After (eager loading — 1 or 2 queries total):",{"type":43,"tag":195,"props":499,"children":501},{"className":197,"code":500,"language":199,"meta":200,"style":200},"\u002F\u002F Option 1: Include (JOIN)\nvar orders = await db.Orders\n    .Include(o => o.Items)\n    .ToListAsync();\n\n\u002F\u002F Option 2: Split query (separate SQL, avoids cartesian explosion)\nvar orders = await db.Orders\n    .Include(o => o.Items)\n    .AsSplitQuery()\n    .ToListAsync();\n\n\u002F\u002F Option 3: Explicit projection (best - only fetches needed columns)\nvar orderSummaries = await db.Orders\n    .Select(o => new OrderSummary\n    {\n        OrderId = o.Id,\n        Total = o.Items.Sum(i => i.Price),\n        ItemCount = o.Items.Count\n    })\n    .ToListAsync();\n",[502],{"type":43,"tag":203,"props":503,"children":504},{"__ignoreMap":200},[505,513,521,529,537,546,554,561,569,578,586,594,603,612,621,630,639,648,657,666],{"type":43,"tag":207,"props":506,"children":507},{"class":209,"line":210},[508],{"type":43,"tag":207,"props":509,"children":510},{},[511],{"type":48,"value":512},"\u002F\u002F Option 1: Include (JOIN)\n",{"type":43,"tag":207,"props":514,"children":515},{"class":209,"line":219},[516],{"type":43,"tag":207,"props":517,"children":518},{},[519],{"type":48,"value":520},"var orders = await db.Orders\n",{"type":43,"tag":207,"props":522,"children":523},{"class":209,"line":228},[524],{"type":43,"tag":207,"props":525,"children":526},{},[527],{"type":48,"value":528},"    .Include(o => o.Items)\n",{"type":43,"tag":207,"props":530,"children":531},{"class":209,"line":237},[532],{"type":43,"tag":207,"props":533,"children":534},{},[535],{"type":48,"value":536},"    .ToListAsync();\n",{"type":43,"tag":207,"props":538,"children":539},{"class":209,"line":246},[540],{"type":43,"tag":207,"props":541,"children":543},{"emptyLinePlaceholder":542},true,[544],{"type":48,"value":545},"\n",{"type":43,"tag":207,"props":547,"children":548},{"class":209,"line":255},[549],{"type":43,"tag":207,"props":550,"children":551},{},[552],{"type":48,"value":553},"\u002F\u002F Option 2: Split query (separate SQL, avoids cartesian explosion)\n",{"type":43,"tag":207,"props":555,"children":556},{"class":209,"line":405},[557],{"type":43,"tag":207,"props":558,"children":559},{},[560],{"type":48,"value":520},{"type":43,"tag":207,"props":562,"children":564},{"class":209,"line":563},8,[565],{"type":43,"tag":207,"props":566,"children":567},{},[568],{"type":48,"value":528},{"type":43,"tag":207,"props":570,"children":572},{"class":209,"line":571},9,[573],{"type":43,"tag":207,"props":574,"children":575},{},[576],{"type":48,"value":577},"    .AsSplitQuery()\n",{"type":43,"tag":207,"props":579,"children":581},{"class":209,"line":580},10,[582],{"type":43,"tag":207,"props":583,"children":584},{},[585],{"type":48,"value":536},{"type":43,"tag":207,"props":587,"children":589},{"class":209,"line":588},11,[590],{"type":43,"tag":207,"props":591,"children":592},{"emptyLinePlaceholder":542},[593],{"type":48,"value":545},{"type":43,"tag":207,"props":595,"children":597},{"class":209,"line":596},12,[598],{"type":43,"tag":207,"props":599,"children":600},{},[601],{"type":48,"value":602},"\u002F\u002F Option 3: Explicit projection (best - only fetches needed columns)\n",{"type":43,"tag":207,"props":604,"children":606},{"class":209,"line":605},13,[607],{"type":43,"tag":207,"props":608,"children":609},{},[610],{"type":48,"value":611},"var orderSummaries = await db.Orders\n",{"type":43,"tag":207,"props":613,"children":615},{"class":209,"line":614},14,[616],{"type":43,"tag":207,"props":617,"children":618},{},[619],{"type":48,"value":620},"    .Select(o => new OrderSummary\n",{"type":43,"tag":207,"props":622,"children":624},{"class":209,"line":623},15,[625],{"type":43,"tag":207,"props":626,"children":627},{},[628],{"type":48,"value":629},"    {\n",{"type":43,"tag":207,"props":631,"children":633},{"class":209,"line":632},16,[634],{"type":43,"tag":207,"props":635,"children":636},{},[637],{"type":48,"value":638},"        OrderId = o.Id,\n",{"type":43,"tag":207,"props":640,"children":642},{"class":209,"line":641},17,[643],{"type":43,"tag":207,"props":644,"children":645},{},[646],{"type":48,"value":647},"        Total = o.Items.Sum(i => i.Price),\n",{"type":43,"tag":207,"props":649,"children":651},{"class":209,"line":650},18,[652],{"type":43,"tag":207,"props":653,"children":654},{},[655],{"type":48,"value":656},"        ItemCount = o.Items.Count\n",{"type":43,"tag":207,"props":658,"children":660},{"class":209,"line":659},19,[661],{"type":43,"tag":207,"props":662,"children":663},{},[664],{"type":48,"value":665},"    })\n",{"type":43,"tag":207,"props":667,"children":669},{"class":209,"line":668},20,[670],{"type":43,"tag":207,"props":671,"children":672},{},[673],{"type":48,"value":536},{"type":43,"tag":263,"props":675,"children":676},{},[677],{"type":43,"tag":422,"props":678,"children":679},{},[680],{"type":48,"value":681},"When to use Split vs Single query:",{"type":43,"tag":113,"props":683,"children":684},{},[685,701],{"type":43,"tag":117,"props":686,"children":687},{},[688],{"type":43,"tag":121,"props":689,"children":690},{},[691,696],{"type":43,"tag":125,"props":692,"children":693},{},[694],{"type":48,"value":695},"Scenario",{"type":43,"tag":125,"props":697,"children":698},{},[699],{"type":48,"value":700},"Use",{"type":43,"tag":141,"props":702,"children":703},{},[704,717,734,750],{"type":43,"tag":121,"props":705,"children":706},{},[707,712],{"type":43,"tag":148,"props":708,"children":709},{},[710],{"type":48,"value":711},"1 level of Include",{"type":43,"tag":148,"props":713,"children":714},{},[715],{"type":48,"value":716},"Single query (default)",{"type":43,"tag":121,"props":718,"children":719},{},[720,725],{"type":43,"tag":148,"props":721,"children":722},{},[723],{"type":48,"value":724},"Multiple Includes (Cartesian risk)",{"type":43,"tag":148,"props":726,"children":727},{},[728],{"type":43,"tag":203,"props":729,"children":731},{"className":730},[],[732],{"type":48,"value":733},"AsSplitQuery()",{"type":43,"tag":121,"props":735,"children":736},{},[737,742],{"type":43,"tag":148,"props":738,"children":739},{},[740],{"type":48,"value":741},"Include with large child collections",{"type":43,"tag":148,"props":743,"children":744},{},[745],{"type":43,"tag":203,"props":746,"children":748},{"className":747},[],[749],{"type":48,"value":733},{"type":43,"tag":121,"props":751,"children":752},{},[753,758],{"type":43,"tag":148,"props":754,"children":755},{},[756],{"type":48,"value":757},"Need transaction consistency",{"type":43,"tag":148,"props":759,"children":760},{},[761],{"type":48,"value":762},"Single query",{"type":43,"tag":188,"props":764,"children":766},{"id":765},"step-3-use-notracking-for-read-only-queries",[767],{"type":48,"value":768},"Step 3: Use NoTracking for read-only queries",{"type":43,"tag":263,"props":770,"children":771},{},[772,777],{"type":43,"tag":422,"props":773,"children":774},{},[775],{"type":48,"value":776},"Change tracking overhead is significant.",{"type":48,"value":778}," Disable it when you don't need to update entities:",{"type":43,"tag":195,"props":780,"children":782},{"className":197,"code":781,"language":199,"meta":200,"style":200},"\u002F\u002F Per-query\nvar products = await db.Products\n    .AsNoTracking()\n    .Where(p => p.IsActive)\n    .ToListAsync();\n\n\u002F\u002F Global default for read-heavy apps\nservices.AddDbContext\u003CAppDbContext>(options =>\n    options.UseSqlServer(connectionString)\n           .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));\n",[783],{"type":43,"tag":203,"props":784,"children":785},{"__ignoreMap":200},[786,794,802,810,818,825,832,840,848,856],{"type":43,"tag":207,"props":787,"children":788},{"class":209,"line":210},[789],{"type":43,"tag":207,"props":790,"children":791},{},[792],{"type":48,"value":793},"\u002F\u002F Per-query\n",{"type":43,"tag":207,"props":795,"children":796},{"class":209,"line":219},[797],{"type":43,"tag":207,"props":798,"children":799},{},[800],{"type":48,"value":801},"var products = await db.Products\n",{"type":43,"tag":207,"props":803,"children":804},{"class":209,"line":228},[805],{"type":43,"tag":207,"props":806,"children":807},{},[808],{"type":48,"value":809},"    .AsNoTracking()\n",{"type":43,"tag":207,"props":811,"children":812},{"class":209,"line":237},[813],{"type":43,"tag":207,"props":814,"children":815},{},[816],{"type":48,"value":817},"    .Where(p => p.IsActive)\n",{"type":43,"tag":207,"props":819,"children":820},{"class":209,"line":246},[821],{"type":43,"tag":207,"props":822,"children":823},{},[824],{"type":48,"value":536},{"type":43,"tag":207,"props":826,"children":827},{"class":209,"line":255},[828],{"type":43,"tag":207,"props":829,"children":830},{"emptyLinePlaceholder":542},[831],{"type":48,"value":545},{"type":43,"tag":207,"props":833,"children":834},{"class":209,"line":405},[835],{"type":43,"tag":207,"props":836,"children":837},{},[838],{"type":48,"value":839},"\u002F\u002F Global default for read-heavy apps\n",{"type":43,"tag":207,"props":841,"children":842},{"class":209,"line":563},[843],{"type":43,"tag":207,"props":844,"children":845},{},[846],{"type":48,"value":847},"services.AddDbContext\u003CAppDbContext>(options =>\n",{"type":43,"tag":207,"props":849,"children":850},{"class":209,"line":571},[851],{"type":43,"tag":207,"props":852,"children":853},{},[854],{"type":48,"value":855},"    options.UseSqlServer(connectionString)\n",{"type":43,"tag":207,"props":857,"children":858},{"class":209,"line":580},[859],{"type":43,"tag":207,"props":860,"children":861},{},[862],{"type":48,"value":863},"           .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking));\n",{"type":43,"tag":263,"props":865,"children":866},{},[867],{"type":43,"tag":422,"props":868,"children":869},{},[870,872,878],{"type":48,"value":871},"Use ",{"type":43,"tag":203,"props":873,"children":875},{"className":874},[],[876],{"type":48,"value":877},"AsNoTrackingWithIdentityResolution()",{"type":48,"value":879}," when the query returns duplicate entities to avoid duplicated objects in memory.",{"type":43,"tag":188,"props":881,"children":883},{"id":882},"step-4-use-compiled-queries-for-hot-paths",[884],{"type":48,"value":885},"Step 4: Use compiled queries for hot paths",{"type":43,"tag":195,"props":887,"children":889},{"className":197,"code":888,"language":199,"meta":200,"style":200},"\u002F\u002F Define once as static\nprivate static readonly Func\u003CAppDbContext, int, Task\u003COrder?>> GetOrderById =\n    EF.CompileAsyncQuery((AppDbContext db, int id) =>\n        db.Orders\n            .Include(o => o.Items)\n            .FirstOrDefault(o => o.Id == id));\n\n\u002F\u002F Use repeatedly — skips query compilation overhead\nvar order = await GetOrderById(db, orderId);\n",[890],{"type":43,"tag":203,"props":891,"children":892},{"__ignoreMap":200},[893,901,909,917,925,933,941,948,956],{"type":43,"tag":207,"props":894,"children":895},{"class":209,"line":210},[896],{"type":43,"tag":207,"props":897,"children":898},{},[899],{"type":48,"value":900},"\u002F\u002F Define once as static\n",{"type":43,"tag":207,"props":902,"children":903},{"class":209,"line":219},[904],{"type":43,"tag":207,"props":905,"children":906},{},[907],{"type":48,"value":908},"private static readonly Func\u003CAppDbContext, int, Task\u003COrder?>> GetOrderById =\n",{"type":43,"tag":207,"props":910,"children":911},{"class":209,"line":228},[912],{"type":43,"tag":207,"props":913,"children":914},{},[915],{"type":48,"value":916},"    EF.CompileAsyncQuery((AppDbContext db, int id) =>\n",{"type":43,"tag":207,"props":918,"children":919},{"class":209,"line":237},[920],{"type":43,"tag":207,"props":921,"children":922},{},[923],{"type":48,"value":924},"        db.Orders\n",{"type":43,"tag":207,"props":926,"children":927},{"class":209,"line":246},[928],{"type":43,"tag":207,"props":929,"children":930},{},[931],{"type":48,"value":932},"            .Include(o => o.Items)\n",{"type":43,"tag":207,"props":934,"children":935},{"class":209,"line":255},[936],{"type":43,"tag":207,"props":937,"children":938},{},[939],{"type":48,"value":940},"            .FirstOrDefault(o => o.Id == id));\n",{"type":43,"tag":207,"props":942,"children":943},{"class":209,"line":405},[944],{"type":43,"tag":207,"props":945,"children":946},{"emptyLinePlaceholder":542},[947],{"type":48,"value":545},{"type":43,"tag":207,"props":949,"children":950},{"class":209,"line":563},[951],{"type":43,"tag":207,"props":952,"children":953},{},[954],{"type":48,"value":955},"\u002F\u002F Use repeatedly — skips query compilation overhead\n",{"type":43,"tag":207,"props":957,"children":958},{"class":209,"line":571},[959],{"type":43,"tag":207,"props":960,"children":961},{},[962],{"type":48,"value":963},"var order = await GetOrderById(db, orderId);\n",{"type":43,"tag":188,"props":965,"children":967},{"id":966},"step-5-avoid-common-query-traps",[968],{"type":48,"value":969},"Step 5: Avoid common query traps",{"type":43,"tag":113,"props":971,"children":972},{},[973,994],{"type":43,"tag":117,"props":974,"children":975},{},[976],{"type":43,"tag":121,"props":977,"children":978},{},[979,984,989],{"type":43,"tag":125,"props":980,"children":981},{},[982],{"type":48,"value":983},"Trap",{"type":43,"tag":125,"props":985,"children":986},{},[987],{"type":48,"value":988},"Problem",{"type":43,"tag":125,"props":990,"children":991},{},[992],{"type":48,"value":993},"Fix",{"type":43,"tag":141,"props":995,"children":996},{},[997,1033,1064,1094,1125],{"type":43,"tag":121,"props":998,"children":999},{},[1000,1017,1022],{"type":43,"tag":148,"props":1001,"children":1002},{},[1003,1009,1011],{"type":43,"tag":203,"props":1004,"children":1006},{"className":1005},[],[1007],{"type":48,"value":1008},"ToList()",{"type":48,"value":1010}," before ",{"type":43,"tag":203,"props":1012,"children":1014},{"className":1013},[],[1015],{"type":48,"value":1016},"Where()",{"type":43,"tag":148,"props":1018,"children":1019},{},[1020],{"type":48,"value":1021},"Loads entire table into memory",{"type":43,"tag":148,"props":1023,"children":1024},{},[1025,1027],{"type":48,"value":1026},"Filter first: ",{"type":43,"tag":203,"props":1028,"children":1030},{"className":1029},[],[1031],{"type":48,"value":1032},".Where().ToList()",{"type":43,"tag":121,"props":1034,"children":1035},{},[1036,1047,1052],{"type":43,"tag":148,"props":1037,"children":1038},{},[1039,1045],{"type":43,"tag":203,"props":1040,"children":1042},{"className":1041},[],[1043],{"type":48,"value":1044},"Count()",{"type":48,"value":1046}," to check existence",{"type":43,"tag":148,"props":1048,"children":1049},{},[1050],{"type":48,"value":1051},"Scans all rows",{"type":43,"tag":148,"props":1053,"children":1054},{},[1055,1056,1062],{"type":48,"value":871},{"type":43,"tag":203,"props":1057,"children":1059},{"className":1058},[],[1060],{"type":48,"value":1061},".Any()",{"type":48,"value":1063}," instead",{"type":43,"tag":121,"props":1065,"children":1066},{},[1067,1084,1089],{"type":43,"tag":148,"props":1068,"children":1069},{},[1070,1076,1078],{"type":43,"tag":203,"props":1071,"children":1073},{"className":1072},[],[1074],{"type":48,"value":1075},".Select()",{"type":48,"value":1077}," after ",{"type":43,"tag":203,"props":1079,"children":1081},{"className":1080},[],[1082],{"type":48,"value":1083},".Include()",{"type":43,"tag":148,"props":1085,"children":1086},{},[1087],{"type":48,"value":1088},"Include is ignored with projection",{"type":43,"tag":148,"props":1090,"children":1091},{},[1092],{"type":48,"value":1093},"Remove Include, use Select only",{"type":43,"tag":121,"props":1095,"children":1096},{},[1097,1108,1113],{"type":43,"tag":148,"props":1098,"children":1099},{},[1100,1106],{"type":43,"tag":203,"props":1101,"children":1103},{"className":1102},[],[1104],{"type":48,"value":1105},"string.Contains()",{"type":48,"value":1107}," in Where",{"type":43,"tag":148,"props":1109,"children":1110},{},[1111],{"type":48,"value":1112},"May not translate, falls to client eval",{"type":43,"tag":148,"props":1114,"children":1115},{},[1116,1117,1123],{"type":48,"value":871},{"type":43,"tag":203,"props":1118,"children":1120},{"className":1119},[],[1121],{"type":48,"value":1122},"EF.Functions.Like()",{"type":48,"value":1124}," for SQL LIKE",{"type":43,"tag":121,"props":1126,"children":1127},{},[1128,1147,1152],{"type":43,"tag":148,"props":1129,"children":1130},{},[1131,1133,1139,1141],{"type":48,"value":1132},"Calling ",{"type":43,"tag":203,"props":1134,"children":1136},{"className":1135},[],[1137],{"type":48,"value":1138},".ToList()",{"type":48,"value":1140}," inside ",{"type":43,"tag":203,"props":1142,"children":1144},{"className":1143},[],[1145],{"type":48,"value":1146},"Select()",{"type":43,"tag":148,"props":1148,"children":1149},{},[1150],{"type":48,"value":1151},"Causes nested queries",{"type":43,"tag":148,"props":1153,"children":1154},{},[1155,1157,1163],{"type":48,"value":1156},"Use projection with ",{"type":43,"tag":203,"props":1158,"children":1160},{"className":1159},[],[1161],{"type":48,"value":1162},"Select",{"type":48,"value":1164}," all the way",{"type":43,"tag":188,"props":1166,"children":1168},{"id":1167},"step-6-use-raw-sql-or-fromsql-for-complex-queries",[1169],{"type":48,"value":1170},"Step 6: Use raw SQL or FromSql for complex queries",{"type":43,"tag":263,"props":1172,"children":1173},{},[1174],{"type":48,"value":1175},"When LINQ can't express it efficiently:",{"type":43,"tag":195,"props":1177,"children":1179},{"className":197,"code":1178,"language":199,"meta":200,"style":200},"var results = await db.Orders\n    .FromSqlInterpolated($@\"\n        SELECT o.* FROM Orders o\n        INNER JOIN (\n            SELECT OrderId, SUM(Price) as Total\n            FROM OrderItems\n            GROUP BY OrderId\n            HAVING SUM(Price) > {minTotal}\n        ) t ON o.Id = t.OrderId\")\n    .AsNoTracking()\n    .ToListAsync();\n",[1180],{"type":43,"tag":203,"props":1181,"children":1182},{"__ignoreMap":200},[1183,1191,1199,1207,1215,1223,1231,1239,1247,1255,1262],{"type":43,"tag":207,"props":1184,"children":1185},{"class":209,"line":210},[1186],{"type":43,"tag":207,"props":1187,"children":1188},{},[1189],{"type":48,"value":1190},"var results = await db.Orders\n",{"type":43,"tag":207,"props":1192,"children":1193},{"class":209,"line":219},[1194],{"type":43,"tag":207,"props":1195,"children":1196},{},[1197],{"type":48,"value":1198},"    .FromSqlInterpolated($@\"\n",{"type":43,"tag":207,"props":1200,"children":1201},{"class":209,"line":228},[1202],{"type":43,"tag":207,"props":1203,"children":1204},{},[1205],{"type":48,"value":1206},"        SELECT o.* FROM Orders o\n",{"type":43,"tag":207,"props":1208,"children":1209},{"class":209,"line":237},[1210],{"type":43,"tag":207,"props":1211,"children":1212},{},[1213],{"type":48,"value":1214},"        INNER JOIN (\n",{"type":43,"tag":207,"props":1216,"children":1217},{"class":209,"line":246},[1218],{"type":43,"tag":207,"props":1219,"children":1220},{},[1221],{"type":48,"value":1222},"            SELECT OrderId, SUM(Price) as Total\n",{"type":43,"tag":207,"props":1224,"children":1225},{"class":209,"line":255},[1226],{"type":43,"tag":207,"props":1227,"children":1228},{},[1229],{"type":48,"value":1230},"            FROM OrderItems\n",{"type":43,"tag":207,"props":1232,"children":1233},{"class":209,"line":405},[1234],{"type":43,"tag":207,"props":1235,"children":1236},{},[1237],{"type":48,"value":1238},"            GROUP BY OrderId\n",{"type":43,"tag":207,"props":1240,"children":1241},{"class":209,"line":563},[1242],{"type":43,"tag":207,"props":1243,"children":1244},{},[1245],{"type":48,"value":1246},"            HAVING SUM(Price) > {minTotal}\n",{"type":43,"tag":207,"props":1248,"children":1249},{"class":209,"line":571},[1250],{"type":43,"tag":207,"props":1251,"children":1252},{},[1253],{"type":48,"value":1254},"        ) t ON o.Id = t.OrderId\")\n",{"type":43,"tag":207,"props":1256,"children":1257},{"class":209,"line":580},[1258],{"type":43,"tag":207,"props":1259,"children":1260},{},[1261],{"type":48,"value":809},{"type":43,"tag":207,"props":1263,"children":1264},{"class":209,"line":588},[1265],{"type":43,"tag":207,"props":1266,"children":1267},{},[1268],{"type":48,"value":536},{"type":43,"tag":51,"props":1270,"children":1272},{"id":1271},"validation",[1273],{"type":48,"value":1274},"Validation",{"type":43,"tag":58,"props":1276,"children":1279},{"className":1277},[1278],"contains-task-list",[1280,1292,1307,1316,1325],{"type":43,"tag":62,"props":1281,"children":1284},{"className":1282},[1283],"task-list-item",[1285,1290],{"type":43,"tag":1286,"props":1287,"children":1289},"input",{"disabled":542,"type":1288},"checkbox",[],{"type":48,"value":1291}," SQL logging shows expected number of queries (no N+1)",{"type":43,"tag":62,"props":1293,"children":1295},{"className":1294},[1283],[1296,1299,1301],{"type":43,"tag":1286,"props":1297,"children":1298},{"disabled":542,"type":1288},[],{"type":48,"value":1300}," Read-only queries use ",{"type":43,"tag":203,"props":1302,"children":1304},{"className":1303},[],[1305],{"type":48,"value":1306},"AsNoTracking()",{"type":43,"tag":62,"props":1308,"children":1310},{"className":1309},[1283],[1311,1314],{"type":43,"tag":1286,"props":1312,"children":1313},{"disabled":542,"type":1288},[],{"type":48,"value":1315}," Hot-path queries use compiled queries",{"type":43,"tag":62,"props":1317,"children":1319},{"className":1318},[1283],[1320,1323],{"type":43,"tag":1286,"props":1321,"children":1322},{"disabled":542,"type":1288},[],{"type":48,"value":1324}," No client-side evaluation warnings in logs",{"type":43,"tag":62,"props":1326,"children":1328},{"className":1327},[1283],[1329,1332],{"type":43,"tag":1286,"props":1330,"children":1331},{"disabled":542,"type":1288},[],{"type":48,"value":1333}," Include\u002Fsplit strategy matches data shape",{"type":43,"tag":51,"props":1335,"children":1337},{"id":1336},"common-pitfalls",[1338],{"type":48,"value":1339},"Common Pitfalls",{"type":43,"tag":113,"props":1341,"children":1342},{},[1343,1359],{"type":43,"tag":117,"props":1344,"children":1345},{},[1346],{"type":43,"tag":121,"props":1347,"children":1348},{},[1349,1354],{"type":43,"tag":125,"props":1350,"children":1351},{},[1352],{"type":48,"value":1353},"Pitfall",{"type":43,"tag":125,"props":1355,"children":1356},{},[1357],{"type":48,"value":1358},"Solution",{"type":43,"tag":141,"props":1360,"children":1361},{},[1362,1383,1412,1431,1460],{"type":43,"tag":121,"props":1363,"children":1364},{},[1365,1370],{"type":43,"tag":148,"props":1366,"children":1367},{},[1368],{"type":48,"value":1369},"Lazy loading silently creating N+1",{"type":43,"tag":148,"props":1371,"children":1372},{},[1373,1375,1381],{"type":48,"value":1374},"Remove ",{"type":43,"tag":203,"props":1376,"children":1378},{"className":1377},[],[1379],{"type":48,"value":1380},"Microsoft.EntityFrameworkCore.Proxies",{"type":48,"value":1382}," or disable lazy loading",{"type":43,"tag":121,"props":1384,"children":1385},{},[1386,1391],{"type":43,"tag":148,"props":1387,"children":1388},{},[1389],{"type":48,"value":1390},"Global query filters forgotten in perf analysis",{"type":43,"tag":148,"props":1392,"children":1393},{},[1394,1396,1402,1404,1410],{"type":48,"value":1395},"Check ",{"type":43,"tag":203,"props":1397,"children":1399},{"className":1398},[],[1400],{"type":48,"value":1401},"HasQueryFilter",{"type":48,"value":1403}," in model config; use ",{"type":43,"tag":203,"props":1405,"children":1407},{"className":1406},[],[1408],{"type":48,"value":1409},"IgnoreQueryFilters()",{"type":48,"value":1411}," if needed",{"type":43,"tag":121,"props":1413,"children":1414},{},[1415,1426],{"type":43,"tag":148,"props":1416,"children":1417},{},[1418,1424],{"type":43,"tag":203,"props":1419,"children":1421},{"className":1420},[],[1422],{"type":48,"value":1423},"DbContext",{"type":48,"value":1425}," kept alive too long",{"type":43,"tag":148,"props":1427,"children":1428},{},[1429],{"type":48,"value":1430},"DbContext should be scoped (per-request); don't cache it",{"type":43,"tag":121,"props":1432,"children":1433},{},[1434,1439],{"type":43,"tag":148,"props":1435,"children":1436},{},[1437],{"type":48,"value":1438},"Batch updates fetching then saving",{"type":43,"tag":148,"props":1440,"children":1441},{},[1442,1444,1450,1452,1458],{"type":48,"value":1443},"EF Core 7+: use ",{"type":43,"tag":203,"props":1445,"children":1447},{"className":1446},[],[1448],{"type":48,"value":1449},"ExecuteUpdateAsync",{"type":48,"value":1451}," \u002F ",{"type":43,"tag":203,"props":1453,"children":1455},{"className":1454},[],[1456],{"type":48,"value":1457},"ExecuteDeleteAsync",{"type":48,"value":1459}," for bulk operations",{"type":43,"tag":121,"props":1461,"children":1462},{},[1463,1474],{"type":43,"tag":148,"props":1464,"children":1465},{},[1466,1468],{"type":48,"value":1467},"String interpolation in ",{"type":43,"tag":203,"props":1469,"children":1471},{"className":1470},[],[1472],{"type":48,"value":1473},"FromSqlRaw",{"type":43,"tag":148,"props":1475,"children":1476},{},[1477,1479,1485],{"type":48,"value":1478},"SQL injection risk — use ",{"type":43,"tag":203,"props":1480,"children":1482},{"className":1481},[],[1483],{"type":48,"value":1484},"FromSqlInterpolated",{"type":48,"value":1486}," (parameterized)",{"type":43,"tag":1488,"props":1489,"children":1490},"style",{},[1491],{"type":48,"value":1492},"html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"items":1494,"total":1600},[1495,1510,1525,1543,1557,1576,1586],{"slug":1496,"name":1496,"fn":1497,"description":1498,"org":1499,"tags":1500,"stars":25,"repoUrl":26,"updatedAt":1509},"analyzing-dotnet-performance","analyze .NET code for performance anti-patterns","Scans .NET code for ~50 performance anti-patterns across async, memory, strings, collections, LINQ, regex, serialization, and I\u002FO with tiered severity classification. Use when analyzing .NET code for optimization opportunities, reviewing hot paths, or auditing allocation-heavy patterns.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1501,1502,1505,1508],{"name":17,"slug":18,"type":15},{"name":1503,"slug":1504,"type":15},"Code Analysis","code-analysis",{"name":1506,"slug":1507,"type":15},"Debugging","debugging",{"name":13,"slug":14,"type":15},"2026-07-12T08:23:25.400375",{"slug":1511,"name":1511,"fn":1512,"description":1513,"org":1514,"tags":1515,"stars":25,"repoUrl":26,"updatedAt":1524},"android-tombstone-symbolication","symbolicate .NET runtime frames in Android tombstones","Symbolicate the .NET runtime frames in an Android tombstone file. Extracts BuildIds and PC offsets from the native backtrace, downloads debug symbols from the Microsoft symbol server, and runs llvm-symbolizer to produce function names with source file and line numbers. USE FOR triaging a .NET MAUI or Mono Android app crash from a tombstone, resolving native backtrace frames in libmonosgen-2.0.so or libcoreclr.so to .NET runtime source code, or investigating SIGABRT, SIGSEGV, or other native signals originating from the .NET runtime on Android. DO NOT USE FOR pure Java\u002FKotlin crashes, managed .NET exceptions that are already captured in logcat, or iOS crash logs. INVOKES Symbolicate-Tombstone.ps1 script, llvm-symbolizer, Microsoft symbol server.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1516,1517,1520,1521],{"name":17,"slug":18,"type":15},{"name":1518,"slug":1519,"type":15},"Android","android",{"name":1506,"slug":1507,"type":15},{"name":1522,"slug":1523,"type":15},"Microsoft","microsoft","2026-07-12T08:23:21.595572",{"slug":1526,"name":1526,"fn":1527,"description":1528,"org":1529,"tags":1530,"stars":25,"repoUrl":26,"updatedAt":1542},"apple-crash-symbolication","symbolicate .NET runtime frames in crash logs","Symbolicate .NET runtime frames in Apple platform .ips crash logs (iOS, tvOS, Mac Catalyst, macOS). Extracts UUIDs and addresses from the native backtrace, locates dSYM debug symbols, and runs atos to produce function names with source file and line numbers. Automatically downloads .dwarf symbols from the Microsoft symbol server using Mach-O UUIDs. USE FOR triaging a .NET MAUI or Mono app crash from an .ips file on any Apple platform, resolving native backtrace frames in libcoreclr or libmonosgen-2.0 to .NET runtime source code, retrieving .ips crash logs from a connected iOS device or iPhone, or investigating EXC_CRASH, EXC_BAD_ACCESS, SIGABRT, or SIGSEGV originating from the .NET runtime. DO NOT USE FOR pure Swift\u002FObjective-C crashes with no .NET components, or Android tombstone files. INVOKES Symbolicate-Crash.ps1 script, atos, dwarfdump, idevicecrashreport.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1531,1532,1533,1536,1539],{"name":17,"slug":18,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1534,"slug":1535,"type":15},"iOS","ios",{"name":1537,"slug":1538,"type":15},"macOS","macos",{"name":1540,"slug":1541,"type":15},"Observability","observability","2026-07-12T08:23:20.369986",{"slug":1544,"name":1544,"fn":1545,"description":1546,"org":1547,"tags":1548,"stars":25,"repoUrl":26,"updatedAt":1556},"assertion-quality","evaluate assertion quality in test suites","Analyzes the variety and depth of assertions across test suites in any language. Use when the user asks to evaluate assertion quality, find shallow tests, identify assertion-free tests (no assertions or only trivial ones like Assert.IsNotNull \u002F toBeTruthy()), flag self-referential or tautological assertions, measure assertion diversity, or audit whether tests verify different facets of behavior. Polyglot: .NET, Python, TS\u002FJS, Java, Go, Ruby, Rust, Swift, Kotlin, PowerShell, C++. DO NOT USE FOR: writing new tests (use code-testing-agent \u002F writing-mstest-tests), mutation reasoning about whether tests would catch a bug (use test-gap-analysis), or a general severity-ranked anti-pattern audit (use test-anti-patterns), fixing or rewriting assertions, or writing, fixing, or modernizing MSTest tests, assertions, or attributes (use writing-mstest-tests).",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1549,1550,1553],{"name":1503,"slug":1504,"type":15},{"name":1551,"slug":1552,"type":15},"QA","qa",{"name":1554,"slug":1555,"type":15},"Testing","testing","2026-07-12T08:23:51.277743",{"slug":1558,"name":1558,"fn":1559,"description":1560,"org":1561,"tags":1562,"stars":25,"repoUrl":26,"updatedAt":1575},"author-component","create and review Blazor components","Create or review Blazor components (.razor files) with correct architecture. USE FOR: writing new Blazor components that do NOT involve JavaScript interop, implementing parameters and EventCallback, RenderFragment slots, component lifecycle (OnInitializedAsync, OnParametersSet), async patterns, IAsyncDisposable, CancellationToken, CSS isolation, code-behind. DO NOT USE FOR: creating new projects (use create-blazor-project), JavaScript interop or calling browser APIs from Blazor (use use-js-interop), forms and validation (use collect-user-input), prerendering issues (use support-prerendering), HTTP data fetching patterns (use fetch-and-send-data), coordinating state between unrelated components (use coordinate-components).\n",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1563,1564,1567,1569,1572],{"name":17,"slug":18,"type":15},{"name":1565,"slug":1566,"type":15},"Blazor","blazor",{"name":1568,"slug":199,"type":15},"C#",{"name":1570,"slug":1571,"type":15},"UI Components","ui-components",{"name":1573,"slug":1574,"type":15},"Web Development","web-development","2026-07-15T06:03:29.216359",{"slug":1577,"name":1577,"fn":1578,"description":1579,"org":1580,"tags":1581,"stars":25,"repoUrl":26,"updatedAt":1585},"binlog-failure-analysis","analyze MSBuild binary logs","Analyze MSBuild binary logs to diagnose build failures. USE FOR: build errors that are unclear from console output, diagnosing cascading failures across multi-project builds, tracing MSBuild target execution order, and generally any MSBuild build issues. Requires an existing .binlog file. DO NOT USE FOR: generating binlogs (use binlog-generation), non-MSBuild build systems.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1582,1583,1584],{"name":1503,"slug":1504,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1522,"slug":1523,"type":15},"2026-07-12T08:21:34.637923",{"slug":1587,"name":1587,"fn":1588,"description":1589,"org":1590,"tags":1591,"stars":25,"repoUrl":26,"updatedAt":1599},"binlog-generation","generate MSBuild binary logs for diagnostics","Generate MSBuild binary logs (binlogs) for build diagnostics and analysis. USE FOR: adding \u002Fbl:{} to any dotnet build, test, pack, publish, or restore command to capture a full build execution trace, prerequisite for binlog-failure-analysis and build-perf-diagnostics skills, enabling post-build investigation of errors or performance. Requires MSBuild 17.8+ \u002F .NET 8 SDK+ for {} placeholder; PowerShell needs -bl:{{}}. DO NOT USE FOR: non-MSBuild build systems (npm, Maven, CMake), analyzing an existing binlog (use binlog-failure-analysis instead).",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1592,1595,1596],{"name":1593,"slug":1594,"type":15},"Build","build",{"name":1506,"slug":1507,"type":15},{"name":1597,"slug":1598,"type":15},"Engineering","engineering","2026-07-19T05:38:19.340791",96,{"items":1602,"total":1707},[1603,1615,1622,1629,1637,1643,1651,1657,1663,1673,1686,1697],{"slug":1604,"name":1604,"fn":1605,"description":1606,"org":1607,"tags":1608,"stars":1612,"repoUrl":1613,"updatedAt":1614},"multithreaded-task-migration","migrate MSBuild tasks to multithreaded mode","Guide for migrating MSBuild tasks to multithreaded mode support, including compatibility red-team review. Use this when converting tasks to thread-safe versions, implementing IMultiThreadableTask, adding TaskEnvironment support, or auditing migrations for behavioral compatibility.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1609,1610,1611],{"name":17,"slug":18,"type":15},{"name":1597,"slug":1598,"type":15},{"name":13,"slug":14,"type":15},5535,"https:\u002F\u002Fgithub.com\u002Fdotnet\u002Fmsbuild","2026-07-22T05:37:33.965588",{"slug":1496,"name":1496,"fn":1497,"description":1498,"org":1616,"tags":1617,"stars":25,"repoUrl":26,"updatedAt":1509},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1618,1619,1620,1621],{"name":17,"slug":18,"type":15},{"name":1503,"slug":1504,"type":15},{"name":1506,"slug":1507,"type":15},{"name":13,"slug":14,"type":15},{"slug":1511,"name":1511,"fn":1512,"description":1513,"org":1623,"tags":1624,"stars":25,"repoUrl":26,"updatedAt":1524},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1625,1626,1627,1628],{"name":17,"slug":18,"type":15},{"name":1518,"slug":1519,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1522,"slug":1523,"type":15},{"slug":1526,"name":1526,"fn":1527,"description":1528,"org":1630,"tags":1631,"stars":25,"repoUrl":26,"updatedAt":1542},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1632,1633,1634,1635,1636],{"name":17,"slug":18,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1534,"slug":1535,"type":15},{"name":1537,"slug":1538,"type":15},{"name":1540,"slug":1541,"type":15},{"slug":1544,"name":1544,"fn":1545,"description":1546,"org":1638,"tags":1639,"stars":25,"repoUrl":26,"updatedAt":1556},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1640,1641,1642],{"name":1503,"slug":1504,"type":15},{"name":1551,"slug":1552,"type":15},{"name":1554,"slug":1555,"type":15},{"slug":1558,"name":1558,"fn":1559,"description":1560,"org":1644,"tags":1645,"stars":25,"repoUrl":26,"updatedAt":1575},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1646,1647,1648,1649,1650],{"name":17,"slug":18,"type":15},{"name":1565,"slug":1566,"type":15},{"name":1568,"slug":199,"type":15},{"name":1570,"slug":1571,"type":15},{"name":1573,"slug":1574,"type":15},{"slug":1577,"name":1577,"fn":1578,"description":1579,"org":1652,"tags":1653,"stars":25,"repoUrl":26,"updatedAt":1585},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1654,1655,1656],{"name":1503,"slug":1504,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1522,"slug":1523,"type":15},{"slug":1587,"name":1587,"fn":1588,"description":1589,"org":1658,"tags":1659,"stars":25,"repoUrl":26,"updatedAt":1599},{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1660,1661,1662],{"name":1593,"slug":1594,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1597,"slug":1598,"type":15},{"slug":1664,"name":1664,"fn":1665,"description":1666,"org":1667,"tags":1668,"stars":25,"repoUrl":26,"updatedAt":1672},"build-parallelism","optimize MSBuild build parallelism","Diagnose and fix under-parallelized MSBuild builds. USE WHEN a multi-project solution build is slower than expected, doesn't speed up when you add cores, pegs a single core while others idle, or you want to know why `-m` isn't helping. Note: `\u002Fmaxcpucount` default is 1 (sequential) — always pass `-m` for parallel builds. Covers finding the critical path (longest serial ProjectReference chain), graph build (`\u002Fgraph`), BuildInParallel, and solution filters (`.slnf`). DO NOT USE FOR: single-project builds, incremental issues (use incremental-build), compilation slowness inside one project (use build-perf-diagnostics), non-MSBuild build systems.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1669,1670,1671],{"name":17,"slug":18,"type":15},{"name":1597,"slug":1598,"type":15},{"name":13,"slug":14,"type":15},"2026-07-19T05:38:18.364937",{"slug":1674,"name":1674,"fn":1675,"description":1676,"org":1677,"tags":1678,"stars":25,"repoUrl":26,"updatedAt":1685},"build-perf-baseline","establish and optimize build performance baselines","Establish build performance baselines and apply systematic optimization techniques. USE FOR: diagnosing slow builds, establishing before\u002Fafter measurements (cold, warm, no-op scenarios), applying optimization strategies like MSBuild Server, static graph builds, artifacts output, and dependency graph trimming. Start here before diving into build-perf-diagnostics, incremental-build, or build-parallelism. DO NOT USE FOR: non-MSBuild build systems, detailed bottleneck analysis (use build-perf-diagnostics after baselining).",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1679,1680,1683,1684],{"name":1597,"slug":1598,"type":15},{"name":1681,"slug":1682,"type":15},"Monitoring","monitoring",{"name":13,"slug":14,"type":15},{"name":1554,"slug":1555,"type":15},"2026-07-12T08:21:35.865649",{"slug":1687,"name":1687,"fn":1688,"description":1689,"org":1690,"tags":1691,"stars":25,"repoUrl":26,"updatedAt":1696},"build-perf-diagnostics","diagnose MSBuild build performance bottlenecks","Diagnose MSBuild build performance bottlenecks using binary log analysis. USE FOR: identifying why builds are slow by analyzing binlog performance summaries, detecting ResolveAssemblyReference (RAR) taking >5s, Roslyn analyzers consuming >30% of Csc time, single targets dominating >50% of build time, node utilization below 80%, excessive Copy tasks, NuGet restore running every build. Covers timeline analysis, Target\u002FTask Performance Summary interpretation, and 7 common bottleneck categories. Use after build-perf-baseline has established measurements. DO NOT USE FOR: establishing initial baselines (use build-perf-baseline first), fixing incremental build issues (use incremental-build), parallelism tuning (use build-parallelism), non-MSBuild build systems.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1692,1693,1694,1695],{"name":17,"slug":18,"type":15},{"name":1506,"slug":1507,"type":15},{"name":1597,"slug":1598,"type":15},{"name":13,"slug":14,"type":15},"2026-07-12T08:21:40.961722",{"slug":1698,"name":1698,"fn":1699,"description":1700,"org":1701,"tags":1702,"stars":25,"repoUrl":26,"updatedAt":1706},"check-bin-obj-clash","detect MSBuild output path conflicts","Detects MSBuild projects with conflicting OutputPath or IntermediateOutputPath. USE FOR: builds failing with 'Cannot create a file when that file already exists', 'The process cannot access the file because it is being used by another process', intermittent build failures that succeed on retry, or missing\u002Foverwritten outputs in multi-project or multi-targeting builds where bin\u002Fobj (or project.assets.json) collide. Common causes: shared OutputPath, missing AppendTargetFrameworkToOutputPath, extra global properties (e.g. PublishReadyToRun), or SetTargetFramework on a ProjectReference to a single-targeting project. DO NOT USE FOR: file access errors unrelated to MSBuild (OS-level locking), single-project single-TFM builds, non-MSBuild build systems.",{"slug":8,"name":9,"logoUrl":10,"githubOrg":8},[1703,1704,1705],{"name":1506,"slug":1507,"type":15},{"name":1597,"slug":1598,"type":15},{"name":1551,"slug":1552,"type":15},"2026-07-19T05:38:14.336279",144]