通常,我这样做:
var a = from p in db.Products
where p.ProductType == "Tee Shirt"
group p by p.ProductColor into g
select new Category {
PropertyType = g.Key,
Count = g.Count() }
但我有这样的代码:
var a = Products
.Where("ProductType == @0", "Tee Shirt")
.GroupBy("ProductColor", "it")
.Select("new ( Key, it.Count() as int )");
我可以更改什么语法以产生相同的结果,即如何从第二个 Linq 语句中进行 Category 的投影?
我知道g和它是相同的并且代表整个表记录,并且我将整个记录拉入只是为了进行计数。我也需要解决这个问题。 编辑:Marcelo Cantos 指出 Linq 足够聪明,不会提取不必要的数据。谢谢!