join-on-equals-into
In C# Linq to Objects, you can use the
clause. DefaultIfEmpty()
join-on-equals-into
Solution on the left external connection
To use the clause to execute the left external connection, please modify the code as follows:
Explanation Where
<code class="language-csharp">List<joinpair> leftFinal = (from l in lefts join r in rights on l.Key equals r.Key into temp from r in temp.DefaultIfEmpty() select new JoinPair { LeftId = l.Id, RightId = r == null ? 0 : r.Id });</code>
in this example). This ensures that all the lines in the left table () are included in the results, even if there is no matching line in the right table ().
Example DefaultIfEmpty()
JoinPair
Considering the code provided for internal connection: lefts
rights
clauses into the following:
This modification will ensure that all the lines in the leftare included in the results, including those lines that are not matched in the right
.<code class="language-csharp">List<joinpair> innerFinal = (from l in lefts from r in rights where l.Key == r.Key select new JoinPair { LeftId = l.Id, RightId = r.Id });</code>
The above is the detailed content of How to Perform Left Outer Joins in LINQ without `join-on-equals-into` Clauses?. For more information, please follow other related articles on the PHP Chinese website!