Part of this article is organized from MSDN
First, the Concept of LINQ:
LINQ is the abbreviation for Language Integrated query (language integration queries), which is integrated in the. NET programming language, which makes query expressions good at compile-time syntax checking, rich metadata, IntelliSense, and other strongly typed languages. Linq is a groundbreaking innovation in Visual Studio 2008 and the. NET Framework version 3.5. It has a bridge between the object domain and the data domain.
Second, the background of the Emergence of LINQ:
Traditionally, queries for data are represented in simple strings, without compile-time type checking or IntelliSense support. In addition, you must learn different query languages for the following data sources: SQL databases, XML documents, various WEB services, and more. LINQ makes queries a first-class language construct in C # and Visual Basic. You can write queries against a collection of strongly typed objects using language keywords and familiar operators. In Visual Studio, you can use visual Basic or C # to write LINQ queries for the following data sources: SQL Server database, XML document, Ado.net DataSet, and support for IEnumerable or generics Ienumera Ble<t>) interface to a collection of arbitrary objects. In addition, LINQ support for the Ado.net Entity Framework is planned, and third parties write LINQ providers for many WEB services and other database implementations.
Third, query expression resolution:
Query resolution Instance
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };//获取数据源。
var lowNums = from n in numbers
where n < 5
select n; //创建查询。
Console.WriteLine("Numbers < 5:");
foreach (var x in lowNums) //执行查询
{
Console.WriteLine(x);
}
The results are:
Numbers < 5:
4
1
3
2
0
Queries that are semantically equivalent to the following method style
var lowNums = numbers
.Where(s => s < 5)
.OrderBy(s => s)
.Select(s => s);