{Joining} Data Sources in Linq | Trickcode

Joining Data Source,LINQ, join clause,SQL,Joins
Share it:
Joining Data Source
There are times where you want to combine values from different data sources into just one result. In LINQ, We can use the join clause or the Join() method to join multiple data sources with properties or fields that can be tested for equivalency. 

With the join clause or the Join() method, you can do inner joins, group joins, or left outer joins. The concepts of joins in LINQ can be compared to joins in SQL. If you know how to do joins in SQL, then you may find the following concepts very familiar. Joins can be very hard to understand for a beginner so I will try my best to explain every concept as clear as possible. 


One can join these two tables which mean, each record of the result of a query is a combination of values from each of the tables. A combined record, for example, will have the Name of the author and the title of the book. An author can have an AuthorId that will uniquely identify him, while a book can have an AuthorId that determines which author wrote that book.

In a join, there is an inner data source and an outer data source. The inner data source contains items that will be combined with the outer data source. Each of the inner item searches for a matching outer item and the two items is joined to create one new record.

The following lessons discuss three types of joins. Inner joins allow you to combine two data sources and create a rectangular result. During an inner join, outer items that have no corresponding inner items are not included in the result set. Inner joins are the simplest and easiest type of join. For example, you can place all the books written by a certain author into a group, and Left outer joins are similar to an inner join as it also creates a rectangular result set, but it also includes outer items which have no corresponding inner item. You will learn more about each of these types of join in the following lessons.


Note that you can also do joins using multiple from clauses but it will require you to properly structure your classes when defining them. For example, an Author can have a property named Books, which contains a set of Book objects that the author writes. Join clause is often effectively used if both classes haven't any defined relationship. We just got to define the key property to be compared during the join operation.
Share it:

LINQ

Post A Comment:

0 comments: