修正多處 LINQ-to-Entities 查詢,避免 Nullable .Contains()、.ToString()、Request[] 直接使用造成翻譯失敗。

API 查詢同步改寫 .Contains()、.OrderBy()、複雜 GroupBy/Math.Round,必要時 materialize 或加 HasValue。
Participation rate / kind breakdown 改在記憶體計算,同時檢查整數陣列 .Contains() 的型別安全性。
This commit is contained in:
2025-11-14 23:40:55 +08:00
parent 4fcbfb3801
commit 27f916eb9c
14 changed files with 245 additions and 115 deletions

View File

@@ -111,6 +111,9 @@ public class statisticsController: ApiController
price = g.Key.price,
count = g.Count(),//功德項目的數量
total_price = g.Where(x => x.price != null).Sum(x => x.price),
// ⚠️ 潛在 N+1 查詢:在 GroupBy 投影中執行新查詢
// g.Select(...).ToList() 會立即執行,然後用 Contains 做子查詢
// 若 g 數量很多,建議重構為 join 或分兩階段查詢以提升效能
followers = _db.pro_order
.Where(h => g.Select(x => x.order_no).Distinct().ToList().Contains(h.order_no))
.Select(k => k.follower.u_name)