LINQ on Query Keyword using C# in ASP.Net

Updated on 06 Apr 2012,
Published on 15 Sep 2010

The "on" is referred to as a contextual keyword in C# that is used in LINQ join clause to specify a join condition. The "on" keyword instructs the compiler that the next query expressions have been defined to specify the comparison between two associated or similar values of two different data sources. Let's understand the use "on" keyword with an example of LINQ join clause query expression:

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 "on" keyword that is used in join clause to specify the comparison test between two similar elements of different data sources.

Continue to next tutorial: LINQ equals Query Keyword using C# in ASP.Net to learn how to specify the equality comparison between the elements of two data source sequences in a query expression.

0 Responses to "LINQ on 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