In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the functions of LINQ query expression". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the functions of LINQ query expressions"?
LINQ query expression is an important part of LINQ function, generally through related keywords to achieve query, modification, deletion and other functions. These keywords are generally similar to those controlled by the database, such as from, select, where and so on.
1.LINQ query expression keyword
Keyword function from specifies the data source and scope variables to be found, multiple from clauses indicate the target data to be returned by the query to find data from multiple data sources select, you can specify filter conditions for any type, even anonymous type where, and multiple where clauses represent juxtaposition conditions, all of which must be met in order to be selected into the sorting field and sorting method of the elements specified by orderby. When there are multiple sort fields, the primary and secondary relationship is determined by the field order, and two sorting methods, ascending and descending, group can be specified.
Specify the grouping field of the element join specifies how multiple data sources are associated
two。 Specify the data source with the from clause
Each LINQ query starts with a from clause, and the from clause includes the following two functions.
Specifies that the query will take the data source.
Define a local variable that represents a single element in the data source.
The format of a single from clause is as follows. Where dataSource represents the data source and localVar represents a single element.
From localVar in dataSource
3. Specify the target data with the select clause
The select clause specifies the type of element in the dataset that produces the result when the query is executed, in the following format:
Select element
4. Specify filter criteria with the where clause
In LINQ, you use the where clause to specify the filter criteria for the query, which is in the following format:
Where expression
Where express is a logical expression that returns a Boolean value of "true" or "false", and multiple conditional filtering can be performed using multiple juxtaposed where clauses in a LINQ query. Elements in the data source can be used as query results only if they meet the conditions of all where clauses at the same time.
5. Sort with the orderby clause
In LINQ, the query results are sorted through the orderby clause, which has the following format:
Orderby element [sortType]
Where element is the field to be sorted, which can be the element in the data source or the result of the operation on the element. SortType is an optional parameter that indicates the sort type, including two optional values, ascending (ascending) and descending (desending). By default, it is ascending.
For LINQ query expressions, note:
The orderby clause is different from the where clause. When there are multiple orderby clauses in a LINQ query, only one orderby clause is valid, and none of the previous orderby clauses is valid.
6. Grouping with group clause
In LINQ, the group clause is used to group the query results. In LINQ, the common format of the group clause is as follows:
Group element by key
Where element represents the element returned as a query result, and key represents the grouping condition. The group clause returns the query result of type IGrouping. Where the type of TKey is the data type of parameter key, and the type of TElement is the data type of parameter element.
Sometimes you need to sort the results of the grouping, query again, and so on. This requires the use of the into keyword to save the results of the group query to a temporary variable, and it must be re-queried with a new select or group clause, or you can use orderby for sorting, filtering with where, and so on. The syntax format of the into keyword is as follows:
Group element by key into tmpGrp
Where tmpGrp represents a local variable, which temporarily saves the results produced by group and provides the use of the following LINQ clause.
At this point, I believe you have a deeper understanding of "what are the functions of LINQ query expressions?" you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.