This is a sample project explained on https://thinkasadev.com that demonstrates the use of .leftJoin() and .RightJoin() in Entity Framework Core 10.
ℹ️ To run this project, you need a running instance of SQL Server.
-
Start SQL Server via Docker
You can start a SQL Server Docker container using the following commands. Be sure to replace
<INSTANCE-NAME>with a strong password and<INSTANCE-NAME>with name of your db instance.Username is
sa
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=<PASSWORD>" -p 1433:1433 --name <INSTANCE-NAME> --hostname <INSTANCE-NAME> -d mcr.microsoft.com/mssql/server:2025-latest-
Create appsettings.json
Duplicate
appsettings.template.jsoninappsettings.jsonand set your connectionstring. -
Apply Migrations to the Database
If docker container is started and
appsettings.jsonis ready, open the Package Manager Console in Visual Studio and run the following command to create the tables and apply the data seeding:Update-Database
Once these steps are completed, the application will be ready to connect to the database and interact with the data.
ℹ️ Go to my blog https://thinkasadev.com and read post about Left Join & Right Join in EF Core 10.
In Service/EmpireService.cs you can find different functions demonstrating left join and right join operations using EF Core 10, EF Core 9 or less and SQL Query.
LEFT JOIN structure:
var query =
await _context.<TABLE_1>.LeftJoin(
_context.<TABLE_2>,
table1 => table1.<ID>,
table2 => table2.<ID>,
(table1, table2) => new
{
Field1 = table1.field1,
Field2 = table2 != null ? table2.field1 : (int?)null
})
.ToListAsync();RIGHT JOIN structure:
var query =
await _context.<TABLE_1>.RightJoin(
_context.<TABLE_2>,
table1 => table1.<ID>,
table2 => table2.<ID>,
(table1, table2) => new
{
Field1 = table1.field1,
Field2 = table2 != null ? table2.field1 : (int?)null
})
.ToListAsync();