一、LINQ关键词
关键字
描述
from Specifies a data source and a range variable (similar to an iteration variable).
where Filters source elements based on one or more Boolean expressions separated by logical AND and OR operators.
select Specifies the type and shape that the elements in the returned sequence will have when the query is executed.
group Groups query results according to a specified key value.
into Provides an identifier that can serve as a reference to the results of a join, group or select clause.
orderby Sorts query results in ascending or descending order based on the default comparer for the element type.
join Joins two data sources based on an equality comparison between two specified matching criteria.
let Introduces a range variable to store sub-expression results in a query expression.
descending Contextual keyword in an
orderby clause.
二、LINQ优缺点
优点
- 对不同的数据源提供了几乎一致的查询操作,这可使我们更多的去关注业务逻辑而非对数据源的操作
- 提供编译期的类型检查
- 在书写LINQ查询表达式时可以使用Visual Studio的智能提示
- 调试方便
缺点
- 对于复杂的查询操作显得力不从心
- 容易写出性能不高的查询表达式