Hi Samantha,
Microsoft has come up with a general-purpose query facilities to the .NET Framework that apply to all
sources of information, not just relational or XML data. This facility
is called .NET Language-Integrated Query (LINQ).
We use the term language-integrated query to indicate that
query is an integrated feature of the developer's primary programming
languages (for example, Visual C#, Visual Basic). Language-integrated
query allows query expressions to benefit from the rich metadata,
compile-time syntax checking, static typing and IntelliSense that was
previously available only to imperative code. Language-integrated query
also allows a single general purpose declarative query facility to be
applied to all in-memory information, not just information from external
sources.
.NET Language-Integrated Query defines a set of general purpose standard query operators
that allow traversal, filter, and projection operations to be expressed
in a direct yet declarative way in any .NET-based programming language.
The standard query operators allow queries to be applied to any IEnumerable<T>-based
information source. LINQ allows third parties to augment the set of
standard query operators with new domain-specific operators that are
appropriate for the target domain or technology. More importantly, third
parties are also free to replace the standard query operators with
their own implementations that provide additional services such as
remote evaluation, query translation, optimization, and so on. By
adhering to the conventions of the LINQ pattern, such implementations enjoy the same language integration and tool support as the standard query operators.
The
extensibility of the query architecture is used in the LINQ project
itself to provide implementations that work over both XML and SQL data.
The query operators over XML (LINQ to XML) use an efficient,
easy-to-use, in-memory XML facility to provide XPath/XQuery
functionality in the host programming language. The query operators over
relational data (LINQ to SQL) build on the integration of SQL-based
schema definitions into the common language runtime (CLR) type system.
This integration provides strong typing over relational data while
retaining the expressive power of the relational model and the
performance of query evaluation directly in the underlying store.
Example code:
using System;
using System.Linq;
using System.Collections.Generic;
class app {
static void Main() {
string[] names = { "Burke", "Connor", "Frank",
"Everett", "Albert", "George",
"Harris", "David" };
IEnumerable<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
foreach (string item in query)
Console.WriteLine(item);
}
}
After compilation:
BURKE
DAVID
FRANK
To understand how language-integrated query works, we need to dissect the
first statement of our program.
IEnumerable<string> query = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
Hope it helps you.
Thank you
Anil