我有ForecastData
列表,它看起來像這樣:很難找到重複表達式
public class ForecastData
{
public string SalesID {get;set;}
public string Customer {get;set;}
public string Vendor {get;set;}
public string Division {get;set;}
public int Year {get;set;}
public decimal Amount {get;set;}
}
我需要顯示每個不同的「SalesID」的列表中爲每個「客戶」有量> 0今年是今年。
目前,我是按客戶進行分組的,但由於我的數據集中可能有多個「金額」相同的客戶和SalesID,所以我沒有得到我期望的結果。我的研究結果表明:
- customer1表用戶1 $ 100
- customer1表用戶1 $ 200
- customer1表用戶1 $ 300
- customer1表用戶2 $ 100
- customer1表用戶2 $ 200
但我要的是
- customer1表用戶1 $ 600
- customer1表用戶2 $ 300
這裏是我的表達:
var forecasts = (List<ForecastData>)cache.Get(_RAW_FORECAST_DATA_KEY, null);
foreach(var custGroup in forecasts.Where(f => f.Year == DateTime.Now.Year).GroupBy(f => f.Customer))
{
if(custGroup.Count() > 1) // There's more than one forecast for this customer
{
foreach(var instance in custGroup)
{
toReturn.Add(new MultipleCustomer(custGroup.Key)
{
Salesperson = instance.SalesPersonId,
Forecast = instance.Amount
});
}
}
}
return toReturn;
看看[this](http://stackoverflow.com/a/491832/1466627)。 –
你肯定需要在你的實例上做一筆總和。你是小組將只對客戶對象進行排序 –