Wiley Professional LINQ 978-0-470-04181-9 Benutzerhandbuch

Produktcode
978-0-470-04181-9
Seite von 14
Klein
c01.tex
V3 - 12/13/2007
1:48pm
Page 3
Project LINQ
I often hear the questions, ‘‘What is LINQ?,’’ ‘‘What does it do?,’’ and ’’Why do we need it?’’
The answer to the first question (and subsequently the other two questions) is that the Language
Integrated Query (LINQ) is a set of standard query operators that provide the underlying query
architecture for the navigation, filtering, and execution operations of nearly every kind of data
source, such as XML (using LINQ to XML, previously known as XLINQ), relational data (using
LINQ to SQL, previously known as DLINQ), ADO.NET DataSets (using LINQ to DataSet), and
in-memory collections.
The best way to begin understanding this wonderful new technology is to take a look at some
history and background on how and why LINQ came to be.
Although the public first became aware of LINQ early in the fall of 2005, LINQ had been in
development since early 2003. The overall LINQ goal was to make it easier for developers to interact
with SQL and XML, primarily because there exists a disconnect between relational data (databases),
XML, and the programming languages that communicate with (that is, work with) each of them.
Most developers understand the concept of object-oriented (OO) programming and its related
technologies and features, such as classes, methods, and objects. Object-oriented programming has
evolved tremendously over the past 10 years or so, but even in its current state, there’s still a gap
when using and integrating OO technology with information that is not natively defined or inherent
to it.
For example, suppose that you want to execute a T-SQL query from within your C# application. It
would look something like this:
private void Form1_Load(object sender, EventArgs e)
{
string ConnectionString = @"Data Source=(local);
Initial Catalog=AdventureWorks;UID=sa;PWD=yourpassword";
using (SqlConnection conn = new SqlConnection(ConnectionString))
{
conn.Open();
SqlCommand cmd = conn.CreateCommand();
COPYRIGHTED MATERIAL