这是我想要的 SQL(ClearinghouseKey
是 a bigint
):
select *
from ConsOutput O
where O.ClearinghouseKey IN (
select distinct P.clearinghouseKey
from Project P
Inner join LandUseInProject L on L.ClearinghouseKey = P.ClearinghouseKey
where P.ProjectLocationKey IN ('L101', 'L102', 'L103')
and L.LandUseKey IN ('U000', 'U001', 'U002', 'U003')
)
内部查询是直截了当的,并在 LINQPad 中给出了正确的结果:
var innerQuery = (from p in Projects
join l in LandUseInProjects on p.ClearinghouseKey equals l.ClearinghouseKey
where locations.Contains(p.ProjectLocationKey)
&& (landuses.Contains(l.LandUseKey))
select new { p.ClearinghouseKey }).Distinct();
但是外部查询给出了错误:Type arguments from ...Contains..cannot be inferred from usage:
var returnQuery = from o in OperOutput
where (innerQuery).Contains(o.ClearinghouseKey)
select o;
是因为 ClearinghouseKey 是一个 bigint 吗?还有其他方法可以编写此查询吗?
谢谢,珍妮