林克:为什么我的智商是可查询的.Intersect抛出了一个异常

本文关键字:异常 一个 Intersect 我的 为什么 查询 林克 | 更新日期: 2023-09-27 18:21:44

我有以下LINQ语句,以及现有的变量IEnumerable<int> conceptIdsint companyId:

from c in dbContext.stt_concept
let A = from compDict in dbContext.stt_company_dictionary
        where compDict.company_id == companyId
        select compDict.dictionary_id
let B = from c2 in dbContext.stt_concept
        where A.Contains(c2.dictionary_id)
        select c2.id
select B.Intersect(conceptIds))

但是,这会引发一个异常,并显示消息"不支持指定的方法"。内部异常的TargetSite属性提到了DbIntersectExpression,所以我认为Intersect的使用有问题。

然而,根据MSDN,源是一个IQueryable,参数是一个IEnumerable,两者都包含相同的类型(int,或者说intelligense让我相信)。

我对Intersect的使用是错误的还是其他原因?

林克:为什么我的智商是可查询的.Intersect抛出了一个异常

(from c in dbContext.stt_concept
join compDict in dbContext.stt_company_dictionary 
        on c.dictionary_id equals compDict.dictionary_id
where compDict.company_id == companyId
select c.id)
.Intersect(conceptIds)

这不是你想做的吗?