Perform Inner Join in Linq using C#

In relational database terms, an inner join produces a result set in which each element of the first collection appears one time for every matching element in the second collection. If an element in the first collection has no matching elements, it does not appear in the result set. The Join method, which is called by the join clause in C#, implements an inner join.

Language Integrated Query (LINQ, pronounced “link”) is a Microsoft .NET Framework component that adds native data querying capabilities to .NET languages, released initially as a significant part of .NET Framework 3.5 in 2007.

In this post, I will show you how to generate inner join using LINQ to SQL. For this post, I am going to use the Categories and Product table of northwind.
LINQ to SQL - Inner Join
Let’s imagine that you want to fetch CategoryNameandProductName from the above table using LINQ.

var query=from p in Products
          join c in Categories
          on p.CategoryID equals c.CategoryID
          select new
          {
          CategoryName=c.CategoryName,
          ProductName=p.ProductName
          };

LINQ to SQL - Inner Join

Please do not post any spam link in the comment box😊

إرسال تعليق (0)
أحدث أقدم