Raw SQL Queries and Split Queries
Explore how to execute raw SQL queries in Entity Framework Core when LINQ falls short and discover split queries to efficiently load related data while avoiding data duplication and performance issues. This lesson helps you understand and apply these techniques within your C# projects.
We'll cover the following...
We'll cover the following...
Overview
In this lesson, we’ll review the following topics:
- Raw SQL queries
- Split queries
Note: The outputs from the projects in this lesson contain the results of sample codes and logs of the translated SQL queries used.
Raw SQL queries
Raw SQL queries provide a powerful medium to interact with relational databases. They are beneficial when we cannot express the desired query with LINQ.
We’ll demonstrate them using the C# console project below:
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/QueryData.dll",
"args": [],
"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}Demonstrating raw SQL queries
Click the ...