You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用HashSet筛选Order表数据时调用ToListAsync报错:Type bool does not contain member ToList

HashSet筛选Order表数据时调用ToListAsync报错:Type bool does not contain member ToList

嘿,这个问题就是个超常见的小语法失误啦!你看最后那段查询Order表的代码:

orders = await _context.Order
.Where(x => ids2.Contains(x.ORDERMAPID)
.ToListAsync();

你在Where方法里的lambda表达式只写了左括号,没补闭合的右括号!编译器会把ToListAsync()当成是ids2.Contains(x.ORDERMAPID)这个bool类型结果的调用方法,但bool根本没有ToListAsync成员,自然就抛出这个报错了。

只需要补上缺失的右括号就行,修正后的代码是这样的:

orders = await _context.Order
    .Where(x => ids2.Contains(x.ORDERMAPID)) // 补上这个右括号就搞定啦
    .ToListAsync();

另外给你个小提醒,写LINQ查询的时候可以借助IDE的括号高亮提示,写完快速扫一眼括号配对情况,这种小失误很容易被忽略,但排查起来又有点懵😅

备注:内容来源于stack exchange,提问作者kaielx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.20 08:18:03