LINQ study Note 1

Source: Internet
Author: User

1. The LINQ query operation contains the following three different and independent actions:
Get Data Source
Create Query
Execute Query

2. There are two types of execution of the LINQ query:
※Delayed execution
When creating a query, the query variable itself does not execute the query, does not contain any data, and does not take any other action. It is only a query placeholder and an ienumerable object. The query is executed only when the elements of this object are enumerated.
※Execute now
Any LINQ query that returns a single value will be executed immediately, such as Count and Max. You can also call the tolist and toarray methods to force the query to be executed immediately. This method is useful when you want to cache the query results.

3, T-SQL query according to the following order in a certain logic processing query:
(8) Select
(9) Top
(1) From
(3) join
(2) On
(4) Where
(5) group
(6)
(7) having
(10) order
The execution of a LINQ query is similar to that of a T-SQL query.

4. Use VaR as little as possible when the type is known. Excessive use of VaR will reduce the readability of source code for subsequent developers.

5. The LINQ provider is a library that can implement the functions provided by the standard query operator for a specific type of data source, it is responsible for executing a given query or handing it over to another engine for execution. LINQ has multiple providers: LINQ to XML, LINQ to datasets, LINQ to objects, and LINQ to SQL.

6. Int [] number1 = {1, 2, 3, 4, 5, 6, 7, 8, 9 };

Int [] number2 = {1, 2, 3, 4, 5, 6, 7, 8, 9 };

VaR F1 = number1.sequenceequal (number2 );

VaR F2 = number1.equals (number2 );

F1 returns true, F2 returns false, because sequenceequal enumerates two data sources in parallel and compares whether the corresponding elements are the same, while equal compares whether the same object is referenced.

LINQ study Note 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.