我有一个可以存放库存项目的表格。这些股票项目具有以下属性如何将左连接加入到另一个左连接
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(A商店)或2(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
我认为你可以找到适合在这里你的问题的详细信息:HTTP:/ /stackoverflow.com/questions/448203/linq-to-sql-using-group-by-and-countdistinct – Matheno