Linq

1 基本语法
  IEnumerable<int> scoreQuery =
            from score in scores
            where score > 80
            select score;


2 分组
var queryGroupByAverages = from student in students
                               group new { student.FirstName, student.LastName }
                                    by student.ExamScores.Average() > 75 into studentGroup
                               select studentGroup;

3 分组子查询

    var queryGroupMax =
        from student in students
        group student by student.Year into studentGroup
        select new
        {
            Level = studentGroup.Key,
            HighestScore =
            (from student2 in studentGroup
             select student2.ExamScores.Average()).Max()
        };

4 动态筛选选(在运行时动态指定谓词筛选器)

        var queryNames =
            from student in students
            let i = student.ID.ToString()
            where ids.Contains(i)
            select new { student.LastName, student.ID };

http://msdn.microsoft.com/zh-cn/library/bb397676.aspx

posted @ 2011-07-19 15:58  无法更新的~  阅读(239)  评论(0编辑  收藏  举报