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

@@ -96,13 +96,14 @@ public class bed_kindController : ApiController
qry = qry.Where(o => o.bed_type == q.bed_type);
if (!string.IsNullOrEmpty(q.bed_type_txt))
{
List<string> _bednums = new List<string>();
// ❌ 錯誤寫法: List<string> _bednums = new List<string>(); _bednums.Add(ii.Key.ToString()); qry = qry.Where(o => _bednums.Contains(o.bed_type.Value.ToString()));
// LINQ to Entities 無法轉換資料庫欄位的 .ToString(),改為整數陣列比較
List<int> _bednums = new List<int>();
foreach (var ii in tdesc)
if(ii.Value.IndexOf(q.bed_type_txt) > -1)
_bednums.Add(ii.Key.ToString());
_bednums.Add(ii.Key);
qry = qry.Where(o => _bednums.Contains( o.bed_type.Value.ToString()));
qry = qry.Where(o => _bednums.Contains(o.bed_type ?? 0));
}
if (q.inTime.HasValue )
{