C #9. Basic Knowledge,
C #9. Basic Knowledge
Prepared by Zhu, reproduced please indicate from Zhu jiayuan http://blog.csdn.net/zhgl7688
1. Use the query syntax and method syntax for LINQ query. The former is similar to the SQL statement, and is written in the form of a query expression. The latter is in the form of a command and can be combined with standard methods.
2. Two types of results are returned for a Linq query: One enumeration and one scalar value.
3. Structure of the Linq query expression: it consists of the from clause after the query body. Clause appears in a certain order. The from clause and selet... The group clause is required. Other clauses are optional.
4. The Linq query expression is different from the select clause in SQL. The former is at the end of the expression, and the latter is before the expression.
For example, select the number of items in the arrs dataset to be less than 13;
Linq: from item in arrs where item <13 select item;
SQL: select item from arrs where item <13
5. The from clause and foreach statements of the Linq query expression are different: the former does not execute any code, and is used to create an enumerated object that stores the query variables, while the latter executes its subject.
6. Join clause:FromSInStudentsJoinCInCoursesOnS. stidEqualsC. stid
7. Join in Linq accepts two sets to create a temporary object set. Each element contains the original members of the two original sets.
8. The Let clause accepts an expression operation and assigns it to an identifier that needs to be used in other operations.
9. The Where clause removes items that do not meet the specified conditions based on subsequent operations. There can be any number of where clauses.
10. The Order by clause accepts an expression and returns results based on the expression. The default values are ascending, ascending, and descending. There can be any number of clauses.
11. The query result of linq can be composed of items in the original set, fields of items in the original set, or anonymous types. Anonymous type example: select new {s. LastName, s. FirstName, s. Major };
12. The group clause groups select objects according to some standards. A key is a group item, for example, group student by student. Major;
13. The query continuation clause can accept a portion of the query results and assign a name to them so that they can be used in another part of the query. Example: from a in groupA join B in groupB on a equals B into groupAandB from c ingroupAandB select c;
14. standard query operators are composed of a series of APIs. The queried collection object is called a sequence. It must implement the IEnumerable <T> interface, and standard query operators use method syntax.
15. Signature of the standard query operator: public and static must be declared. this extension indicator is available before the first parameter, and IEnumerable <T> is used as the first parameter type. For example, public static T First <T> (this IEnumerable <T> source );
16. predicate: a parameter delegate that generates a Boolean value.
17. Linq to XML markup language: XML labels are case sensitive and spaces in the document are valid.
Prepared by Zhu, reproduced please indicate from Zhu jiayuan http://blog.csdn.net/zhgl7688