<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="http://aspnet.4guysfromrolla.com/rss/rss2html.xsl" version="1.0"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>4GuysFromRolla.com :: An Extensive Examination of LINQ Article Series</title>
<link>http://aspnet.4guysfromrolla.com/articles/021109-1.aspx</link>
<description>An article series on LINQ.</description>
<language>en-us</language>
<webMaster>mitchell@4guysfromrolla.com (Scott Mitchell)</webMaster>
<atom:link href="http://aspnet.4guysfromrolla.com/rss/linq.xml" rel="self" type="application/rss+xml" />

<item>
	<title>An Extensive Examination of LINQ: Extending LINQ - Adding Query Operators</title>
	<description>
&lt;p&gt;
As discussed in earlier installments of this article series - most notably in &lt;a href="http://www.4guysfromrolla.com/articles/021109-1.aspx"&gt;An Introduction to LINQ&lt;/a&gt;
and &lt;a href="http://www.4guysfromrolla.com/articles/040109-1.aspx"&gt;The Standard Query Operators&lt;/a&gt; - one of LINQ's primary components is its set of &lt;i&gt;standard
query operators&lt;/i&gt;. A query operator is a method that operates on a sequence of data and performs some task based on that data, are implemented as 
&lt;a href="http://www.4guysfromrolla.com/articles/120507-1.aspx"&gt;extension methods&lt;/a&gt; on types that implement
the &lt;a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;&lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; interface&lt;/a&gt;. Some of the standard query operators that we've 
explored throughout the articles in this series include: &lt;code&gt;Count&lt;/code&gt;, &lt;code&gt;Average&lt;/code&gt;, &lt;code&gt;First&lt;/code&gt;, &lt;code&gt;Skip&lt;/code&gt;, &lt;code&gt;Take&lt;/code&gt;, &lt;code&gt;Where&lt;/code&gt;,
and &lt;code&gt;OrderBy&lt;/code&gt;, among others.
&lt;p&gt;
While these standard query operators provide a great detail of functionality, there may be situations where they fall short. The good news is that it's quite easy to create
your own query operators. Underneath the covers query operators are just methods that extend types that implement &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; and iterate over the 
sequence performing some task, such as computing the total number of items in the sequence, computing the average, filtering the results, or ordering them. This article examines 
how to extend LINQ's functionality by creating your own extension methods. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://www.4guysfromrolla.com/articles/070710-1.aspx</link>
	<guid>http://www.4guysfromrolla.com/articles/070710-1.aspx</guid>
	<pubDate>Wed, 7 Jul 2010 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: Querying and Searching XML Documents Using LINQ to XML</title>
	<description>
&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/XML"&gt;XML&lt;/a&gt; is an increasingly popular way to encode documents, data, and electronic messages. Over the years Microsoft has offered
a variety of libraries to facilitate creating, modifying, querying, and searching XML documents. &lt;a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx"&gt;&lt;i&gt;LINQ to 
XML&lt;/i&gt;&lt;/a&gt; is a relatively new set of XML-related classes in the .NET Framework (found in the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.aspx"&gt;&lt;code&gt;System.Xml.Linq&lt;/code&gt; 
namespace&lt;/a&gt;), which enable developers to work with XML documents using LINQ's features, syntax, and semantics. As discussed in an earlier article, 
&lt;a href="http://www.4guysfromrolla.com/articles/112509-1.aspx"&gt;Introducing LINQ to XML&lt;/a&gt;, LINQ to XML is a simpler and easier to use API than previous libraries.
Because LINQ to XML can utilize LINQ's &lt;a href="http://www.4guysfromrolla.com/articles/041509-1.aspx"&gt;query syntax&lt;/a&gt; and assortment of 
&lt;a href="http://www.4guysfromrolla.com/articles/040109-1.aspx"&gt;standard query operators&lt;/a&gt;, LINQ to XML code is usually very terse and readable.
&lt;/p&gt;&lt;p&gt;
This article continues our look at LINQ to XML. Specifically, we explore how to query XML documents using axis methods as well as how to search and filter XML documents
using both LINQ's &lt;code&gt;Where&lt;/code&gt; method and &lt;a href="http://en.wikipedia.org/wiki/XPath"&gt;XPath expressions&lt;/a&gt;. Read on to learn more!
&lt;/p&gt;&lt;p&gt;
&lt;i&gt;Note: If you have not yet read &lt;a href="http://www.4guysfromrolla.com/articles/112509-1.aspx"&gt;Introducing LINQ to XML&lt;/a&gt; please do so before reading this article...&lt;/i&gt;
&lt;/p&gt;
	</description>
	<link>http://www.4guysfromrolla.com/articles/062310-1.aspx</link>
	<guid>http://www.4guysfromrolla.com/articles/062310-1.aspx</guid>
	<pubDate>Wed, 23 Jun 2010 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: Introducing LINQ to XML</title>
	<description>
&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/XML"&gt;XML&lt;/a&gt; is an increasingly popular way to encode documents, data, and electronic messages. There are a number of ways to programmatically
create, modify, and search XML files. Since its inception, the .NET Framework's &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.aspx"&gt;&lt;code&gt;System.Xml&lt;/code&gt; 
namespace&lt;/a&gt; has included classes for programmatically working with XML documents. For instance, the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.aspx"&gt;&lt;code&gt;XmlReader&lt;/code&gt;&lt;/a&gt; 
and &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmlwriter.aspx"&gt;&lt;code&gt;XmlWriter&lt;/code&gt; classes&lt;/a&gt; offer developers a means to read from or write to
XML files in a fast, forward-only manner, while the &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.aspx"&gt;&lt;code&gt;XmlDocument&lt;/code&gt; class&lt;/a&gt;
allows developers to work with an XML document as an in-memory tree representation.
&lt;/p&gt;&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx"&gt;&lt;i&gt;LINQ to XML&lt;/i&gt;&lt;/a&gt; is a new set of XML-related classes in the .NET Framework (found in the 
&lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.linq.aspx"&gt;&lt;code&gt;System.Xml.Linq&lt;/code&gt; namespace&lt;/a&gt;), which enable developers to work with XML documents using
LINQ's features, syntax, and semantics. Compared to .NET's existing XML APIs, LINQ to XML is a simpler, easier to use API. For a given task, LINQ to XML code is typically shorter 
and more readable than code that uses the &lt;code&gt;XmlDocument&lt;/code&gt; or &lt;code&gt;XmlReader&lt;/code&gt;/&lt;code&gt;XmlWriter&lt;/code&gt; classes. And perhaps most importantly, LINQ to XML allows
you to leverage your existing knowledge and familiarity with LINQ's standard query operators and query syntax.
&lt;/p&gt;&lt;p&gt;
This article is the first in a series of articles that examines LINQ to XML. This installment introduces the LINQ to XML API, examines some of the more pertinent classes
in the &lt;code&gt;System.Xml.Linq&lt;/code&gt; namespace, and shows how to perform a number of common XML tasks using the API. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://www.4guysfromrolla.com/articles/112509-1.aspx</link>
	<guid>http://www.4guysfromrolla.com/articles/112509-1.aspx</guid>
	<pubDate>Wed, 25 Nov 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: Grouping and Joining Data</title>
	<description>
&lt;p&gt;
As discussed in &lt;a href="http://www.4guysfromrolla.com/articles/021109-1.aspx"&gt;An Introduction to LINQ&lt;/a&gt;, one of the cornerstones of LINQ is the
&lt;i&gt;standard query operators&lt;/i&gt;, which are a set of extension methods on the &lt;code&gt;IEnumerable&lt;/code&gt; interface added to the .NET Framework version 3.5. The standard
query operators can be applied to any enumeration - any collection of "things." In &lt;a href="http://www.4guysfromrolla.com/articles/040109-1.aspx"&gt;The Standard Query
Operators&lt;/a&gt; installment we looked at some of the more common query operators, such as &lt;code&gt;Where&lt;/code&gt;, &lt;code&gt;Select&lt;/code&gt;, &lt;code&gt;OrderBy&lt;/code&gt;, and others.
Each standard query operator can be classified as a certain type of operator. There are aggregation operators like &lt;code&gt;Count&lt;/code&gt;, &lt;code&gt;Sum&lt;/code&gt;, and &lt;code&gt;Max&lt;/code&gt;;
element operators like &lt;code&gt;First&lt;/code&gt;, &lt;code&gt;Last&lt;/code&gt;, and &lt;code&gt;ElementAt&lt;/code&gt; let you pick out a specific element from a sequence; and the ordering operators
&lt;code&gt;OrderBy&lt;/code&gt; and &lt;code&gt;OrderByDescending&lt;/code&gt; order the elements of a sequence based on a specified sorting criteria.
&lt;/p&gt;&lt;p&gt;
Another class of query operators that we've yet to explore are &lt;i&gt;grouping and joining operators&lt;/i&gt;. The grouping and joining operators work with two (or more) sequences
and combine them together, much like how a &lt;code&gt;JOIN&lt;/code&gt; in SQL combines records from two (or more) tables into a single resultset. Through LINQ's standard query operators
(or via its &lt;a href="http://www.4guysfromrolla.com/articles/041509-1.aspx"&gt;query syntax&lt;/a&gt;), it is possible to perform: nested (or grouped) queries; cross joins, or
the &lt;a href="http://en.wikipedia.org/wiki/Cartesian_product"&gt;Cartesian product&lt;/a&gt; of two sequences; inner joins; and left outer joins.
&lt;/p&gt;&lt;p&gt;
This article explores the grouping and joining operators available in LINQ with a number of examples in both Visual Basic and C#. As with the previous installments in this
article series, the complete code is available for download. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://www.4guysfromrolla.com/articles/080509-1.aspx</link>
	<guid>http://www.4guysfromrolla.com/articles/080509-1.aspx</guid>
	<pubDate>Wed, 5 Aug 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>


<item>
	<title>An Extensive Examination of LINQ: Using the Query Syntax</title>
	<description>
&lt;p&gt;
LINQ's &lt;a href="http://aspnet.4guysfromrolla.com/articles/040109-1.aspx"&gt;standard query operators&lt;/a&gt; provide dozens of built-in techniques for programmatically enumerating,
aggregating, selecting, and filtering data. These standard query operators are implemented as extension functions on the &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; interface and therefore
available to any object that implements this interface, which includes arrays, the collection classes in the &lt;code&gt;System.Collections&lt;/code&gt; namespace, and objects that are
composed of a set of enumerable items (such as a &lt;code&gt;DataTable&lt;/code&gt;). The examples we've explored in this tutorial series thus far have primarily used these standard query 
operators in their extension method form, namely as methods applied to &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; collections. For example, the following snippet uses this style of
syntax to query a collection of &lt;code&gt;Employee&lt;/code&gt; objects, returning a list of the employees' &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Salary&lt;/code&gt; for those employees that make more
than $100,000 per year, sorted by salary in descending order.
&lt;/p&gt;&lt;table border="0"&gt;
&lt;tr&gt;&lt;td width="100%" bgcolor="#cccccc"&gt;
&lt;code&gt;
// C# - get the Name and Salary of employees that make more than $100,000, ordered from the highest paid on down&lt;br /&gt;
List&lt;Employee&gt; emps = ...;&lt;br /&gt;
var SalaryReport = emps&lt;span style="color:red;"&gt;.Where( p =&gt; p.Salary &gt; 100000M )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.OrderByDescending( p =&gt; p.Salary )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Select( p =&gt; new { p.Name, p.Salary } )&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
' VB - get the Name and Salary of employees that make more than $100,000, ordered from the highest paid on down&lt;br /&gt;
Dim emps As List(Of Employee) = ...&lt;br /&gt;
Dim SalaryReport = emps.&lt;span style="color:red;"&gt;Where(Function(p) p.Salary &gt; 100000) _&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.OrderByDescending(Function(p) p.Salary) _&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.Select(Function(p) New With {p.Name, p.Salary})&lt;/span&gt;&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;
While the above syntax certainly works, it is not the most human-friendly syntax. For starters, it's quite verbose. It's also unlike the data querying syntax most developers
are familiar with - SQL. To address these shortcomings, Microsoft added a number of language enhancements to C# 3.0 and Visual 9, which are the versions that shipped with the 
.NET Framework 3.5 and Visual Studio 2008. In addition to &lt;a href="http://aspnet.4guysfromrolla.com/articles/021809-1.aspx"&gt;extension methods, implicitly typed variables,
object initializers&lt;/a&gt;, &lt;a href="http://aspnet.4guysfromrolla.com/articles/031109-1.aspx"&gt;lambda expressions, and anonymous types&lt;/a&gt;, Microsoft also added a new &lt;i&gt;query
syntax&lt;/i&gt; that allows developers to write LINQ queries in a SQL-like syntax. The following code is semantically equivalent to the example above, but uses the &lt;i&gt;query syntax&lt;/i&gt;
(or &lt;i&gt;query expressions&lt;/i&gt;) instead of the extension method syntax:
&lt;/p&gt;&lt;table border="0"&gt;
&lt;tr&gt;&lt;td width="100%" bgcolor="#cccccc"&gt;
&lt;code&gt;
// C# - get the Name and Salary of employees that make more than $100,000, ordered from the highest paid on down&lt;br /&gt;
List&lt;Employee&gt; emps = ...;&lt;br /&gt;
var SalaryReport = &lt;span style="color:red;"&gt;from p in emps&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;where p.Salary &gt; 100000M &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;orderby p.Salary descending&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;select new { p.Name, p.Salary } )&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
' VB - get the Name and Salary of employees that make more than $100,000, ordered from the highest paid on down&lt;br /&gt;
Dim emps As List(Of Employee) = ...&lt;br /&gt;
Dim SalaryReport = &lt;span style="color:red;"&gt;From p In emps _&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Where p.Salary &gt; 100000 _&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Order By p.Salary _&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Select New With {p.Name, p.Salary}&lt;/span&gt;
&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;
This query syntax is another &lt;a href="http://en.wikipedia.org/wiki/Syntactic_sugar"&gt;syntactic sugar&lt;/a&gt; language enhancement. When compiled, the above code is translated
into calls to the corresponding standard query operators.
&lt;/p&gt;&lt;p&gt;
This article explores both C# and Visual Basic's query syntax. We'll discuss the mapping between the query syntax and LINQ's standard
query operators, as well as see a number of query syntax examples. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/041509-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/041509-1.aspx</guid>
	<pubDate>Wed, 15 Apr 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: The Standard Query Operators</title>
	<description>
&lt;p&gt;
&lt;i&gt;Query operators&lt;/i&gt; are methods that work with a sequence of data and perform some task based on the data. They are created as extension methods on the
&lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; interface, which is the interface implemented by classes that hold enumerable data. For example, arrays and the classes in the 
&lt;code&gt;System.Collections&lt;/code&gt; and &lt;code&gt;System.Collections.Generic&lt;/code&gt; namespaces all implement &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt;. In 
&lt;a href="http://aspnet.4guysfromrolla.com/articles/032509-1.aspx"&gt;The Ins and Outs of Query Operators&lt;/a&gt; we looked at how to create your own query operator that, once created,
can be applied to any enumerable object.
&lt;/p&gt;&lt;p&gt;
While it is possible to create your own query operators, the good news is that the .NET Framework already ships with a bevy of useful query operators. These query operators
are referred to as the &lt;i&gt;standard query operators&lt;/i&gt; and are one of the primary pieces of LINQ. The standard query operators include functionality for aggregating sequences
of data, concatenating two sequences, converting sequences from one type to another, and splicing out a particular element from the enumeration. There are also standard
query operators for generating new sequences, grouping and joining sequences, ordering the elements in sequences, filtering the data in a sequence, and partitioning the
sequence.
&lt;/p&gt;&lt;p&gt;
All together, there are more than 40 standard query operators. This article explores some of the more germane ones, giving examples of the standard query operator in use and 
examining its underlying source code. There are also several demos included in the download available at the end of the article. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/040109-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/040109-1.aspx</guid>
	<pubDate>Wed, 01 Apr 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: The Ins and Outs of Query Operators</title>
	<description>
&lt;p&gt;
As discussed in &lt;a href="http://aspnet.4guysfromrolla.com/articles/021109-1.aspx"&gt;An Introduction to LINQ&lt;/a&gt;, LINQ is composed of three main components:
&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Language Extensions,&lt;/li&gt;
	&lt;li&gt;Standard Query Operators, and&lt;/li&gt;
	&lt;li&gt;LINQ Providers.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The previous two installments - &lt;a href="http://aspnet.4guysfromrolla.com/articles/021809-1.aspx"&gt;Extension Methods, Implicitly Typed Variables, and Object Initializers&lt;/a&gt; and
&lt;a href="http://aspnet.4guysfromrolla.com/articles/031109-1.aspx"&gt;Lambda Expressions and Anonymous Types&lt;/a&gt; - explored the language extensions added to C# 3.0 and Visual Basic
9 that allow for LINQ's unique syntax. But these language extensions are merely syntactic sugar; they make it possible for developers to write more concise and readable code, but
they don't actually perform any operations. The real workhorse of LINQ is the standard query operators.
&lt;/p&gt;
&lt;p&gt;
LINQ's standard query operators are a collection of &lt;i&gt;query operators&lt;/i&gt;. Query operators are methods that walk through a sequence of data and perform some task based
on that data, and are implemented as extension methods on the &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; interface. We've already seen a handful of standard query operators in use in 
previous installments, such as &lt;code&gt;Where&lt;/code&gt;, &lt;code&gt;Count&lt;/code&gt;, and &lt;code&gt;Average&lt;/code&gt;. This article explores the inner workings of query operators, which is essential
to understanding how LINQ's standard query operators work. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/032509-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/032509-1.aspx</guid>
	<pubDate>Wed, 25 Mar 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: Lambda Expressions and Anonymous Types</title>
	<description>
&lt;p&gt;
The previous installment in this article series, &lt;a href="http://aspnet.4guysfromrolla.com/articles/021809-1.aspx"&gt;Extension Methods, Implicitly Typed Variables, and Object 
Initializers&lt;/a&gt;, examined three new features to the C# 3.0 and Visual Basic 9 languages that allow for developers to use LINQ's standard query operators and providers to 
write SQL-like query syntax to work with common data stores. But extension methods, implicitly typed variables, and object initializers are only part of the story. Two additional
language features - lambda expressions and anonymous types - are also essential ingredients in LINQ's unique syntax.
&lt;/p&gt;&lt;p&gt;
Recall that LINQ's standard query operators can work with any collection of data that implements the &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt; interface. Some of the standard query 
operators perform rather straightforward operations on the collection; the &lt;code&gt;Count&lt;/code&gt; standard query operator, for instance, simply returns the number of elements 
in the collection. However, other standard query operators are more flexible, allowing the page developer to dictate how the operator will work. The &lt;code&gt;Where&lt;/code&gt; standard query
operator is such an example - it filters the elements in the collection based on a developer-specified filtering method. But just how can a developer "pass" a method to the
&lt;code&gt;Where&lt;/code&gt; standard query operator as an input parameter? The .NET Framework has long supported the notion of delegates, which are type-safe function pointers. However, 
the syntax for delegates is a little confusing and verbose. Lambda expressions offer a much more terse syntax for defining an anonymous method.
&lt;/p&gt;&lt;p&gt;
Anonymous types allow for inline types. In a nutshell, anonymous types let you clump a set of values together into a new type without having to first declare the type
via a class. For example, imagine that you have a collection of &lt;code&gt;Employee&lt;/code&gt; objects, where each &lt;code&gt;Employee&lt;/code&gt; object has properties like &lt;code&gt;Name&lt;/code&gt;, 
&lt;code&gt;Salary&lt;/code&gt;, &lt;code&gt;HireDate&lt;/code&gt;, and so on. You may want to apply some filtering condition on this collection using the &lt;code&gt;Where&lt;/code&gt; standard query operator and
then &lt;i&gt;project&lt;/i&gt; the collection of &lt;code&gt;Employee&lt;/code&gt; objects into a collection of objects that includes just the &lt;code&gt;Name&lt;/code&gt; and &lt;code&gt;Salary&lt;/code&gt; properties.
With anonymous types this style of projection is straightforward and natural. Without anonymous types you would first have to create a class like &lt;code&gt;EmployeeSimplified&lt;/code&gt; 
that contained only those two properties of interest.
&lt;/p&gt;&lt;p&gt;
This article provides an overview of lambda expressions and anonymous types. These two language enhancements, along with extension methods, implicitly typed variables, and object 
initializers, are what allows for LINQ's query syntax. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/031109-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/031109-1.aspx</guid>
	<pubDate>Wed, 11 Mar 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: Extension Methods, Implicitly Typed Variables, and Object Initializers</title>
	<description>
&lt;p&gt;
One of the more substantive additions to the .NET Framework 3.5 and C# 3.0 and Visual Basic 9 languages was LINQ, a set of classes along with language enhancements that
allow developers to use a common library and SQL-like query syntax to work with common data stores. The initial article in this series,
&lt;a href="http://aspnet.4guysfromrolla.com/articles/021109-1.aspx"&gt;An Introduction to LINQ&lt;/a&gt;, provided an overview of LINQ and its core pieces: the standard query
operators, the language extensions that allow for LINQ's query syntax, and LINQ providers. We also looked at some simple LINQ examples using both the standard query operators
and the query syntax.
&lt;/p&gt;&lt;p&gt;
LINQ's standard query operators - &lt;code&gt;Select&lt;/code&gt;, &lt;code&gt;Where&lt;/code&gt;, &lt;code&gt;OrderBy&lt;/code&gt;, &lt;code&gt;Average&lt;/code&gt;, and so on -  can be used as if they were instance methods
of any object that implements &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt;. For example, given a string array named &lt;code&gt;FileNames&lt;/code&gt; we can determine how many strings in the array start
with the letter "S" by using the &lt;code&gt;Where&lt;/code&gt; and &lt;code&gt;Count&lt;/code&gt; standard query operators like so:
&lt;/p&gt;&lt;table border="0"&gt;
&lt;tr&gt;&lt;td width="100%" bgcolor="#cccccc"&gt;
&lt;code&gt;
string[] FileNames = { ... };&lt;br /&gt;
int count = FileNames.&lt;span style="color:red;"&gt;Where(name =&gt; name.StartsWith("S")).Count()&lt;/span&gt;;&lt;/code&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;&lt;p&gt;
The &lt;code&gt;Where&lt;/code&gt; method and &lt;code&gt;Count&lt;/code&gt; methods look like they are members of the &lt;code&gt;Array&lt;/code&gt; class. However, they are defined in the 
&lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.aspx"&gt;&lt;code&gt;Enumerable&lt;/code&gt; class&lt;/a&gt; in the 
&lt;a href="http://msdn.microsoft.com/en-us/library/system.linq.aspx"&gt;&lt;code&gt;System.Linq&lt;/code&gt; namespace&lt;/a&gt; as &lt;i&gt;extension methods&lt;/i&gt; on the &lt;code&gt;IEnumerable&lt;T&gt;&lt;/code&gt;
interface. Also note the syntax that is used to specify the input parameter for the Where method: &lt;code&gt;name =&gt; name.StartsWith("S")&lt;/code&gt;. This syntax is a &lt;i&gt;lambda
expression&lt;/i&gt; and provides a shorthand notation for developers to define a function.
&lt;/p&gt;&lt;p&gt;
This installment (and the next one) explore the language enhancements Microsoft made to C# 3.0 and Visual Basic 9 in more depth. (C# 3.0 and Visual Basic 9 are, at the time 
of this writing, the most recent versions of these two programming languages. They are the versions that were released with the .NET Framework 3.5 and Visual Basic 2008.)
The key language enhancements that make LINQ possible include: extension methods; implicitly typed variables; object initializers; lambda expressions; and anonymous types.
This article explores the first three of these language extensions; the latter two will be covered in the next installment. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/021809-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/021809-1.aspx</guid>
	<pubDate>Wed, 18 Feb 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>

<item>
	<title>An Extensive Examination of LINQ: An Introduction to LINQ</title>
	<description>
&lt;p&gt;
&lt;a href="http://en.wikipedia.org/wiki/Language_Integrated_Query"&gt;LINQ&lt;/a&gt;, or &lt;b&gt;L&lt;/b&gt;anguage &lt;b&gt;IN&lt;/b&gt;tegrated &lt;b&gt;Q&lt;/b&gt;uery, is set of classes added to the .NET Framework 3.5
along with language enhancements added to C# 3.0 and Visual Basic 9, the versions of the language that ship with Visual Studio 2008. LINQ adds a rich, standardized
query syntax as a first-class citizen in .NET programming languages that allows developers to interact with any type of data.
&lt;/p&gt;&lt;p&gt;
Consider a typical data-driven application. There may be times when you are working with a database, displaying records or editing, inserting, and deleting data. Certain
parts of the application may require retrieving certain elements from an XML file, or constructing an XML file based on user input. Or perhaps you have a collection of objects
returned from a business object that you now want to work with by sorting them, computing the average value of a particular numeric property value, and displaying only those
objects that meet a specified criteria. Prior to LINQ, working with each data source requires writing a different style of code. Moreover, working with external resources like
data bases, XML files, and the like typically involves communicating with that external resource in some syntax specific to that resource. To retrieve data from a database you
need to send it a string that contains the SQL query to execute; likewise, to work with a subset of XML elements in an XML document involves specifying an XPath expression
in the form of a string. The idea is that using LINQ you can work with disparate data sources using a similar style without having to know a separate syntax for communicating 
with the data source (e.g., SQL or XPath) and without having to resort to passing opaque strings to external resources. 
&lt;/p&gt;&lt;p&gt;
This article is the first in a series of articles that explores the goals of LINQ, its underpinnings, its syntax, and LINQ providers like LINQ to Objects, LINQ to XML, LINQ
to SQL, and so forth. This inaugural article offers an overview of LINQ, looks at some simple examples of using the LINQ classes and syntax, and examines the core LINQ
classes in the .NET Framework. Read on to learn more!
&lt;/p&gt;
	</description>
	<link>http://aspnet.4guysfromrolla.com/articles/021109-1.aspx</link>
	<guid>http://aspnet.4guysfromrolla.com/articles/021109-1.aspx</guid>
	<pubDate>Wed, 11 Feb 2009 00:00:00 GMT</pubDate>
	<author>mitchell@4guysfromrolla.com (Scott Mitchell)</author>
</item>
</channel>
</rss>

