Member-only story
11 No-Nonsense EF Core Raw SQL Tricks I Use When LINQ Starts Acting Cute (.NET 10)
If You want the full source code Click :Here
EF Core is like that friend who insists they can cook anything… until you ask for a spicy, database-specific dish with a CTE, a window function, and a weird hint to the query planner.
That’s when Raw SQL becomes your escape hatch.
In .NET 10 projects you’ll still use the same EF Core raw SQL patterns you’ve seen in recent EF Core versions:
- Query with
FromSqlRaw/FromSqlInterpolated - Execute commands with
ExecuteSqlRaw/ExecuteSqlInterpolated - Project to non-entity types with
Database.SqlQueryRaw<T>/Database.SqlQuery<T>(when available in your EF Core version)
I can’t verify any brand-new EF Core 10 API changes from here, so I’ll stick to the stable, widely-used surface area that works across modern EF Core.
1) When Raw SQL is the right tool (and when it’s just you panicking)
Use raw SQL when you need:
- CTEs, window functions, hints, vendor-specific functions
- Performance for a query LINQ can’t express cleanly