Entity Framework Core 8 Preview 1 introduces the ability to execute raw SQL select statements and map results to any unmapped type, not just natively supported primitives or database model entities. Using the new SqlQuery and SqlQueryRaw methods, developers can now write custom SQL queries returning arbitrary types. This is useful for data migration tasks, hot code paths requiring fine-grained query optimization, and reducing dependencies on additional ORMs like Dapper. The feature returns IQueryable, and SqlQuery is preferred over SqlQueryRaw to avoid SQL injection risks.

6m read timeFrom timdeschryver.dev
Post cover image
Table of contents
How to write raw SQL queriesWhy raw SQL queries are importantConclusion
2 Impressions