.NET Language Integrated Query (LINQ)
The next big challenge in programming technology is to reduce the complexity of accessing and integrating information from relational databases and XML.
Rather than adding relational or XML-specific features to our programming languages at runtime, we can take a more general approach and could add 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).
.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
The extensibility of the query architecture is that it can be used to provide implementations that work over both XML and SQL data. The query operators over XML (XLinq) 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 (DLinq) build on the integration of SQL-based schema definitions into the CLR type system.
LINQ is built entirely on general purpose language features, some of which are new to C# 3.0 and Visual Basic 9.0. Each of these features has utility of its own, yet collectively these features provide an extensible way to define queries and queryable API’s.
In general, the developer is free to use named methods, anonymous methods, or lambda expressions with query operators. Lambda expressions have the advantage of providing the most direct and compact syntax for authoring. More importantly, lambda expressions can be compiled as either code or data, which allows lambda expressions to be processed at runtime by optimizers, translators, and evaluators.
Note: Lambda expressions are similar to CLR delegates and must adhere to a method signature defined by a delegate type.
eg for Lamda:
IEnumerable<string> expr = from s in names
where s.Length == 5
orderby s
select s.ToUpper();
The code written above is equivalent to this lamda expression:
Eg IEnumerable<string> expr = names
.Where(s => s.Length ==5)
.OrderBy(s => s)
.Select(s => s.ToUpper());




