Database Reference
In-Depth Information
Note SQOs are a collection of methods that form the LINQ pattern. SQO methods operate on sequences, where
a sequence represents an object whose type implements the interface IEnumerable<T> or the interface
IOueryable<T> . The SQO provides query capabilities including filtering, projection, aggregation, sorting, and so
forth.
LINQ to ADO.NET (also known as LINQ-enabled ADO .NET) deals with data from external sources,
basically anything ADO.NET can connect to. Any class that implements IEnumerable<T> or
IOueryable<T> (in the System.Linq namespace) can be queried with SQOs. The LINQ to ADO.NET
functionality can be achieved by using the System.Data.Linq namespace.
LINQ to XML is a comprehensive API for in-memory XML programming. Like the rest of LINQ, it
includes SQOs, and it can also be used in concert with LINQ to ADO.NET, but its primary purpose is to
unify and simplify the kinds of things that disparate XML tools, such as XQuery, XPath, and XSLT, are
typically used to do. The LINQ to XML functionality can be achieved by using the System.Xml.Linq
namespace.
Note LINQ on the .NET Compact Framework includes a subset of the desktop LINQ features. One of the
differences between LINQ on the .NET Framework and LINQ on the .NET Compact Framework is that on the .NET
Compact Framework, only SQOs are supported. LINQ to DataSets and LINQ to DataTables are supported, and LINQ
to XML is also supported except for XPath extensions.
In this chapter, we'll work with the techniques LINQ to Objects, LINQ to SQL, and LINQ to DataSets,
since they're most closely related to the C# 2012 database programming we've covered in this topic.
LINQ Project Structure
Visual Studio 2012 allows you to use LINQ queries. To create a LINQ project, follow these steps:
1. Open Visual Studio 2012 and select File New Project.
2. In the New Project dialog box that appears, by default .NET Framework 4.5 is
chosen in the list of available .NET Framework versions supported by Visual
Studio 2012. Select the type of project you want the LINQ feature to be part of.
For this example, we will be using a Windows Forms Application project.
3. Specify the name Chapter18 for the chosen project, and click OK. A new
Windows Forms application named Chapter18 will be created. Select the
project named Chapter18 underneath the solution and rename it to Linq. Save
all the changes.
4. Open the References folder in Solution Explorer. You should see Linq-related
assembly references added by default, as shown in Figure 18-2.
 
Search WWH ::




Custom Search