2015-02-09 37 views
0

您好我有這個查詢計算所有銷售的產品,現在我想更改它,因此它計算特定客戶的產品數量。任何人都可以幫助我嗎?表格=客戶一個交易one2many交易項目many2one產品many2one產品類型針對特定客戶的Linq計數產品

  var query = from product in cse.tblTransactionItems 
         group product by product.tblProduct.Description into g 
         select new { ProductId = g.Key, totalUnitsSold = g.Count() }; 

回答

0

您可以考慮按多列分組。

var query = from product in cse.tblTransactionItems 
      group product by new 
      { 
       product.tblProduct.Description, 
       product.tblProduct.Customer // put the customer here. 
      } into g 
      select new 
      { 
       Product = g.Key.Description, 
       Customer = g.Key.Customer, 
       totalUnitsSold = g.Count() 
      }; 

這樣totalUnitsSold是一個總的特定客戶和產品。

注意:如果您的客戶在另一個表中,則需要先加入。以上只是假設客戶是您現有表格的一部分。

+0

謝謝你工作得很好。 – 2015-02-09 15:32:25

相關問題