LINQ unifies the data access mode, which serves as a bridge between the programming language and data. LINQ framework: it consists of three parts: Language extension, LINQ build block, and Assembly provision.
For the following code:
Varquery = from book in SampleData. Books
Where book. Title = "Funny Stories"
Orderby book. Title
Select new {book. Title, book. Price };
It is equivalent:
Varquery = SampleData. Books
. Where (book => book. Title = "Funny Stories ")
. OrderBy (book => book. Title)
. Select (book => new {book. Title, book. Price });
The compiler converts it to the following call:
IEnumerable <double> query = Enumerable. Select <int, double> (
Enumerable. OrderBy (\
Enumerable. Where (
SampleData. Books,
Book => book. Title = "Funny Stories "),
Book => book. Title ),
Book => new {book. Title, book. Price });
Many LINQ methods are defined in the System. Linq. Enumerable class. These methods are implemented as extension methods.
. NET implements the IEnumerable <T> interface object to become an iteratable object, the iteratable object will return an iterator (the object that implements the IEnumerator <T> Interface ), you can use the iterator to traverse the iterated objects.
Some extension methods in the Enumerable class accept parameters of the IEnumerable <T> type and return the results of IEnumerable <T>. Therefore, they are equivalent to filters in the processing process. These methods only return iteratable objects, and do not return the query results. They are executed only when an iteratable object is called (for example, foreach, this is a very important feature of LINQ-latency query.