【发布时间】:2015-04-08 18:58:54
【问题描述】:
我有一张存放库存物品的桌子。这些库存商品具有以下属性
public class StockItem
{
public int BrandId { get; set; }
public int ModelId { get; set; }
public decimal Price { get; set; }
public int StoreId { get; set; }
}
其中 StoreId 可以是 1(Store A)或 2(Store B)
我想对这些项目进行分组以获得以下结果
BrandId
ModelId
Count in Store A
count in Store B
我以前使用过group by 子句,但不是这样。我应该如何编写 linQ 语句来完成我的任务?
总结一下我有以下记录
Id BrandId ModelId Price StoreId
=========================================
1 1 1 11 1
2 1 1 11 1
3 1 2 12 1
4 1 2 12 2
5 1 1 11 2
并试图得到以下结果
BrandId ModelId CountInStoreA CountInStoreB
=================================================
1 1 2 1
1 2 1 1
【问题讨论】:
-
我想你可以在这里找到更多适合你问题的信息:stackoverflow.com/questions/448203/…
标签: c# linq entity-framework group-by