Posts

Showing posts from March 20, 2011

LINQ Query Syntax Tutorial

Probably the most exciting new feature of LINQ is the ability to write in line SQL style queries, known as query expressions (using query syntax).  This tutorial introduces the basic concepts, and comes complete with source code and demo applications. What is LINQ Query Syntax? LINQ query syntax is a set of query keywords built into the .NET framework (3.5 and higher) that allow the developer to write SQL style commands in line straight in the code editor, without the use of quotes. Introduction The .NET framework 3.5 introduces us to the following query keywords; from / in - Specifies the data source where - Conditional boolean expression (e.g. i == 0) orderby (ascending/descending) - Sorts the results into ascending or descending order select - Adds the result to the return type group / by - Groups the results based on a given key There are more keywords that provide additional functionality, but they are outside the scope of this tutorial. Writing your first query The q