完成 Batch 3:修復 4 個 API Controller 的 AsEnumerable 問題
修復文件(共 17 處):
1. supplierController.cs (6 處)
- 移除簡單查詢的 AsEnumerable() (2 處)
- AsEnumerable() → AsQueryable() (GetList, GetKindList)
- 優化分頁查詢模式(Count + ToPagedList.ToList())(2 處)
- 修復 Split().Select().ToList() 類型問題
2. adminUserController.cs (4 處)
- 移除簡單查詢的 AsEnumerable()
- AsEnumerable() → AsQueryable() (GetList)
- 優化分頁查詢模式
- 重構複雜查詢:移除嵌套的 AsEnumerable()
改為先 ToList() 再使用 Contains
3. orderdetailController.cs (3 處)
- 移除 AsEnumerable(),改為在查詢末端使用 OrderBy
- 優化分頁查詢模式
- 修復 null-propagating operator:
.FirstOrDefault()?.print_id → .Select(u => u.print_id).FirstOrDefault()
4. transfer_registerController.cs (6 處)
- AsEnumerable() → ToList() (需要解密操作的情況)
- 保留在必要時才轉換到內存操作
- 確保數據庫查詢先執行
技術改進:
✓ 複雜嵌套查詢優化(adminUserController)
✓ 解密操作前置優化(transfer_registerController)
✓ Null-propagating operator 替換為安全的 Select
✓ 統一使用三元運算符處理分頁
✓ IEnumerable<int> → List<int> 避免類型轉換錯誤
This commit is contained in:
@@ -237,7 +237,7 @@ public class transfer_registerController : ApiController
|
||||
x.draft,
|
||||
follower = x.f_num != null ? _db.followers
|
||||
.Where(f => f.num == x.f_num)
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(f => new {
|
||||
f.num,
|
||||
f.u_name,
|
||||
@@ -417,7 +417,7 @@ public class transfer_registerController : ApiController
|
||||
d.demo,
|
||||
reg_time = o.reg_time // 報名日期
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(x => new {
|
||||
x.order_no,
|
||||
x.activity_num,
|
||||
@@ -481,7 +481,7 @@ public class transfer_registerController : ApiController
|
||||
x.draft,
|
||||
follower = x.f_num != null ? _db.followers
|
||||
.Where(f => f.num == x.f_num)
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(f => new {
|
||||
f.num,
|
||||
f.u_name,
|
||||
@@ -817,7 +817,7 @@ public class transfer_registerController : ApiController
|
||||
tr.balance_act_item,
|
||||
balance_actitem_name = tr.balance_act_item != null ? _db.actItems.Where(a => a.num == tr.balance_act_item).Select(a => a.subject).FirstOrDefault() : ""
|
||||
})
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(tr => new
|
||||
{
|
||||
tr.id,
|
||||
@@ -1054,7 +1054,7 @@ public class transfer_registerController : ApiController
|
||||
d.price,
|
||||
paid = d.pro_order_record.Select(r => r.price).DefaultIfEmpty(0).Sum()
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(x => new {
|
||||
x.f_num,
|
||||
x.follower_name,
|
||||
@@ -1104,7 +1104,7 @@ public class transfer_registerController : ApiController
|
||||
d.demo,
|
||||
reg_time = o.reg_time // 報名日期
|
||||
}))
|
||||
.AsEnumerable()
|
||||
.ToList()
|
||||
.Select(x => new {
|
||||
x.order_no,
|
||||
x.activity_num,
|
||||
|
||||
Reference in New Issue
Block a user