Max
说明:返回集合中元素的最大值;不延迟。生成SQL语句为:SELECT MAX(…) FROM
1.简单形式:
查找任意雇员的最近雇用日期:
var q = db.Employees.Select(e => e.HireDate).Max();
2.映射形式:
查找任意产品的最大库存量:
var q = db.Products.Max(p => p.UnitsInStock);
3.元素:
查找每个类别中单价最高的产品:
var categories = from p in db.Products group p by p.CategoryID into g select new { g.Key, MostExpensiveProducts = from p2 in g where p2.UnitPrice == g.Max(p3 => p3.UnitPrice) select p2 };