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
Users
andPosts
tables on two columns (UserId
and a conditionIsPublished
) using theequals
keyword. - 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 theUserId
column from thePost
entity with theId
column from theUser
entity.
Additional reading at EF Core Join Query - TekTutorialsHub
Referenced in:
Leave a Comment
All fields are required. Your email address will not be published.
Comments