gpt4 book ai didi

c# - LINQ:为什么我的 IQueryable.Intersect 抛出异常

转载 作者:行者123 更新时间:2023-11-29 12:43:18 26 4
gpt4 key购买 nike

我有以下 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 ,或者智能感知让我相信)。

我对 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)

这不是你想做的事吗?

关于c# - LINQ:为什么我的 IQueryable.Intersect 抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25811642/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com