In LINQ, Join operators are used for integrating two data source into one data source which shares some common attributes. For example, in a bank, the manager has two lists, the first list contains the personal details and another list contains the home loan details. Now the manager wants to create a list which contains the names of those peoples who take a home loan and belong to the same place, so he uses join clause to create such type of list.
The join clause always takes two data source, the elements present the data source must contain some property so that it can compare with other data source. The result of the join clause depends upon which type of join clause is used. The most common types of the join are:
- Inner Join
- Cross Join
- Left outer join
- Group join
In LINQ, an inner join is used to serve a result which contains only those elements from the first data source that appears only one time in the second data source. And if an element of the first data source does not have matching elements, then it will not appear in the result data set. Here Join and Inner join are the same.
- All the joins perform by join clause are equijoins.
- It support query syntax in both C# and VB.Net languages.
join … in … on … equals …
- It support method syntax in both C# and VB.Net languages. Here, the join method is overloaded in two different ways:
- Join <TOuter,TInner,TKey,TResult>(IEnumerable <TOuter>, IEnumerable <TInner>, Func <TOuter,TKey>,Func <TInner,TKey>,Func <TOuter,TInner,TResult>): This method allows you to correlate the elements of two sequences based on the given matching keys. Here, the default equality comparer is used to compare keys.
- Join<TOuter,TInner,TKey,TResult>(IEnumerable<TOuter>,IEnumerable<TInner>, Func<TOuter,TKey>,Func<TInner,TKey>,Func<TOuter,TInner,TResult>,IEqualityComparer<TKey>): This method allows you to correlate the elements of two sequences based on matching keys. A specified IEqualityComparer<T> is used to compare keys.
- Join method present in both the Queryable and Enumerable class.
- The working of Join is similar like an inner join in SQL.
- The join clause compares the data sources, according to specified keys using equals keyword, here == is not valid.
Employee and their Salary: Employee Name: Anu Salary: 23000 Employee Name: Mohit Salary: 40000 Employee Name: Sona Salary: 50000 Employee Name: Lana Salary: 60000
Employee Name and their Department: Employee Name: Anu Department: Designing Employee Name: Mohit Department: Developing Employee Name: Sona Department: HR Employee Name: Lana Department: Designing
- Cross Join in LINQ
- C# | Join() Method | Set - 1
- C# | Join Method | Set - 2
- LINQ | Set Operator | Except
- What is Query in LINQ?
- LINQ | Let Keyword
- LINQ | Set Operator | Distinct
- LINQ | Method Syntax
- LINQ | Set Operator | Intersect
- LINQ | Quantifier Operator | All
- LINQ | Set Operator | Union
- LINQ | Partition Operator | Take
- Aggregation Function in LINQ
- LINQ | Element Operator | First
- LINQ | Quantifier Operator | Any
- LINQ | Element Operator | Last
- LINQ | Query Syntax
- LINQ | How to find the sum of the given Sequence?
- LINQ | Filtering Operator | where
- LINQ | Quantifier Operator | Contains
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.