LINQ 基础学习

一、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.
in         Contextual keyword in a join clause.
on        Contextual keyword in a join clause.
equals      Contextual keyword in a join clause.
by        Contextual keyword in a group clause.
ascending     Contextual keyword in an orderby clause.
descending     Contextual keyword in an orderby clause.
 
二、LINQ优缺点

优点

  1. 对不同的数据源提供了几乎一致的查询操作,这可使我们更多的去关注业务逻辑而非对数据源的操作
  2. 提供编译期的类型检查
  3. 在书写LINQ查询表达式时可以使用Visual Studio的智能提示
  4. 调试方便

缺点

  1. 对于复杂的查询操作显得力不从心
  2. 容易写出性能不高的查询表达式

猜你喜欢

转载自www.cnblogs.com/llw1996/p/11743329.html