Successfully added
EF Core
by John
Joining Entities in LINQ
To join a subquery (INNER JOIN table) in EF Core, you can use the Join
method along with LINQ expressions. Below is a example code snippet:
var query = from order in context.Orders
join orderItem in context.OrderItems
on order.OrderId equals orderItem.OrderId
where order.CustomerName == "John Doe"
select new
{
order.OrderId,
order.CustomerName,
orderItem.ProductName,
orderItem.Price
};
The expression on order.OrderId equals orderItem.OrderId
is used to specify the join condition between two tables/entities (Orders
and OrderItems
based on their related columns OrderId
.
Additional Reading at EF Core Inner Join (csharptutorial.net)
Referenced in:
Comments