我很困惑.我从Microsoft LINQ示例站点复制了此代码,但无法进行编译.
我想做类似的事情,但它说它无法解决符号minPrice和一堆其他错误.是什么赋予了?
public void Linq84() { List products = GetProductList(); var categories = from p in products group p by p.Category into g from minPrice = g.Group.Min(p => p.UnitPrice) select new {Category = g.Key, CheapestProducts = g.Group.Where(p => p.UnitPrice == minPrice)}; ObjectDumper.Write(categories, 1); }
CMS.. 7
我认为查询有一些错别字,或者是在Linq的早期阶段制作的.
我会把它重写为:
var categories = from p in products group p by p.Category into g let minPrice = g.Min(p => p.UnitPrice) select new { Category = g.Key, CheapestProducts = g.Where(p => p.UnitPrice == minPrice) };
顺便说一句,作为良好的学习资源,我强烈推荐你LinqPad这是一个很棒的工具和HookedToLinq.
我认为查询有一些错别字,或者是在Linq的早期阶段制作的.
我会把它重写为:
var categories = from p in products group p by p.Category into g let minPrice = g.Min(p => p.UnitPrice) select new { Category = g.Key, CheapestProducts = g.Where(p => p.UnitPrice == minPrice) };
顺便说一句,作为良好的学习资源,我强烈推荐你LinqPad这是一个很棒的工具和HookedToLinq.