LINQ equals Query Keyword using C# in ASP.Net

Updated on 06 Apr 2012,
Published on 15 Sep 2010

The "equals" is referred to as a contextual keyword in C# that is also used in LINQ join clause to compare the similar elements of two different data source sequences. For joining two data source sequences you can use the join clause. The elements of one sequence must contain a property or value corresponding to one of the property of the other data source sequence. The join clause possesses a special "equals" keyword that enables to compare the equality between both the specified keys of the data sources. All joins performed by the LINQ join clause are equijoins. Let's understand the use of "equals" keyword with the help of an example:

Example

// LINQ join query to perform simple inner join
var query = from category in Categories
            join product in Products on category.CategoryID equals product.CategoryID
            select new { category.CategoryName, product.ProductName };

// loop over the query to get the result sequence
foreach (var item in query)
{
    Response.Output.Write("{0}: {1}<br />", item.CategoryName, item.ProductName);
}

The above C# example shows the use "equals" keyword that is used in join clause to specify the equality comparison between two similar elements of different data sources.

Continue to next tutorial: LINQ by Query Keyword using C# in ASP.Net to learn how to specify the grouping criteria in a LINQ query expression.

0 Responses to "LINQ equals Query Keyword using C# in ASP.Net"
Leave a Comment
* required
* required
* will not be published
* optional
* hint: http://www.example.com
  • Subscribe via Email
  • HIRE EzineASP.Net Developers