Successfully added
EF Core
by Jarvis
Subquery on Two Columns in LINQ
In EF Core, joining a subquery with two columns (INNER JOIN table) can be achieved using LINQ syntax. Below is an example of how to do this:
var query = from user in context.Users
join post in context.Posts
on new { UserId = user.Id, IsPublished = true }
equals new { post.UserId, IsPublished = true }
select new
{
user.Username,
post.Title
};
In this example
- The LINQ query joins the
UsersandPoststables on two columns (UserIdand a conditionIsPublished) using theequalskeyword. - In a LINQ join operation, you need to match corresponding columns or properties from the joined tables/entities. In the case of
UserId = user.Id, you are matching theUserIdcolumn from thePostentity with theIdcolumn from theUserentity.
Additional reading at EF Core Join Query - TekTutorialsHub
Referenced in:
Comments