我寫象下面這樣的代碼:LINQ集團通過字符串並計算分組屬性的子屬性
Session["priceRange"] = ranges.Select(r => new PriceRangeGraph
{
Price = Math.Round(r, 2),
Sales = lista.Where(x => ranges.FirstOrDefault(y => y >= x.SalePrice) == r).Sum(x => x.SaleNumber),
SuccessfulSellers = lista.GroupBy(x => x.StoreName).Where(x => ranges.FirstOrDefault(y => y >= x.Select(z => z.SalePrice).FirstOrDefault()) == r && x.Select(h => h.SaleNumber).FirstOrDefault() > 0).Count(),
UnSuccessfulSellers = lista.GroupBy(x => x.StoreName).Where(x => ranges.FirstOrDefault(y => y >= x.Select(z => z.SalePrice).FirstOrDefault()) == r && x.Select(h => h.SaleNumber).FirstOrDefault() == 0).Count(),
}).ToList();
這些代碼兩個問題行:
SuccessfulSellers = lista.GroupBy(x => x.StoreName).Where(x => ranges.FirstOrDefault(y => y >= x.Select(z => z.SalePrice).FirstOrDefault()) == r && x.Select(h => h.SaleNumber).FirstOrDefault() > 0).Count(),
UnSuccessfulSellers = lista.GroupBy(x => x.StoreName).Where(x => ranges.FirstOrDefault(y => y >= x.Select(z => z.SalePrice).FirstOrDefault()) == r && x.Select(h => h.SaleNumber).FirstOrDefault() == 0).Count(),
在銷售物業,你可以看到我正在找到該產品的銷售價格範圍,然後我簡單地將所有銷售額計入給定範圍內。
現在我試圖看看有多少成功/不成功的用戶(使用他們的用戶名)在給定的範圍內銷售。
So for example user test123 made 5 sales, test1234 made 4 sales, test56 made 0 sales in range 0-20$
此範圍的輸出將是:
SuccessfulSellers=2
UnSuccessfulSellers = 1
上面的代碼我試圖不給我在正確的結果...
正如你可以看到我m按用戶的用戶名分組以獲得發生號碼,然後篩選用戶進行銷售的範圍,然後簡單地添加另一個用於過濾= 0銷售和銷售超過0的銷售的語句...
我在這裏做錯了什麼?
任何人? =) – User987
你可以提供更多關於你的模型('範圍'和'lista')的信息,也許一些樣本記錄和你期望的結果是 –