修正多處 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

@@ -128,7 +128,9 @@ public partial class admin_order_index : MyWeb.config
sd.AppendChild(tr);
//查詢要匯出的資料
var aIDt = _db.actItems.Where(f => f.subject.Contains(s_actItemTxt.Value.Trim())).Select(f => f.num.ToString());//品項
// ❌ 錯誤寫法: var aIDt = _db.actItems.Where(f => f.subject.Contains(s_actItemTxt.Value.Trim())).Select(f => f.num.ToString());
// 改為整數陣列,避免後續查詢中使用 .ToString()
var aIDt = _db.actItems.Where(f => f.subject.Contains(s_actItemTxt.Value.Trim())).Select(f => f.num).ToArray();//品項
var qry = _db.pro_order.AsQueryable();
if (!isStrNull(s_order_no.Value))
@@ -140,7 +142,14 @@ public partial class admin_order_index : MyWeb.config
if (!isStrNull(s_subject.Value))
qry = qry.Where(o => o.activity_num.HasValue && o.activity.subject.Contains(s_subject.Value.Trim()));
if (!isStrNull(s_actItemTxt.Value))
qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.ToArray().Contains(f2.actItem_num.ToString())).Count() > 0);
{
// ❌ 錯誤寫法: qry = qry.Where(o => o.pro_order_detail.Where(f2 => f2.order_no == o.order_no && aIDt.ToArray().Contains(f2.actItem_num.ToString())).Count() > 0);
// ✅ 實際比較:僅在 actItem_num 有值時才與整數陣列比對
qry = qry.Where(o => o.pro_order_detail.Any(f2 =>
f2.order_no == o.order_no &&
f2.actItem_num.HasValue &&
aIDt.Contains(f2.actItem_num.Value)));
}
if (!isStrNull(s_keyin1.SelectedValue))
qry = qry.Where(o => o.keyin1 == s_keyin1.SelectedValue);