Database Reference
In-Depth Information
C H A P T E R 18
Using LINQ
Writing software means you need to have a database sitting on the back end, and most of your time goes
into writing queries to retrieve and manipulate data. Whenever someone talks about data, we tend to
think of the information that is contained in a relational database or in an XML document.
The kind of data access that we had prior to the release of .NET 3.5 was meant only for data that
resides in traditional data sources like the two just mentioned. But with the release of .NET 3.5 and
newer versions like .NET 4.0 and .NET 4.5, which have Language Integrated Query (LINQ) incorporated
into them, it is now possible to deal with data residing beyond traditional information storage. For
instance, you can query a generic List type containing a few hundred integer values and write a LINQ
expression to retrieve a subset that meets your criterion, such as either even or odd numbers.
LINQ, as you may have gathered, is one of the major differences between .NET 3.0 and .NET 3.5. It is
a set of features in Visual Studio 2012 that extends powerful query capabilities into the language syntax
of C# and VB .NET.
LINQ introduces a standard, unified, easy-to-learn approach for querying and modifying data and
can be extended to support potentially any type of data store. Visual Studio 2012 includes LINQ provider
assemblies that enable the use of LINQ queries with various types of data sources including relational
data, XML, and in-memory data structures.
In this chapter, we'll cover the following:
Introduction to LINQ
Architecture of LINQ
LINQ project structure
Using LINQ to Objects
Using LINQ to SQL
Using LINQ to XML
Introduction to LINQ
LINQ is an innovation that Microsoft made with the release of Visual Studio 2008 and .NET Framework
version 3.5 that promises to revolutionize the way developers work with data. Microsoft has continued to
improve LINQ with the recent releases of .NET 4.0/4.5 and Visual Studio 2012. As mentioned, LINQ
allows you to query various types of data sources including relational databases, XML documents, and
even in-memory data structures. LINQ supports all these types of data stores with the help of LINQ
query expressions of first-class language constructs in C# 2012. LINQ offers the following advantages:
 
Search WWH ::




Custom Search