1

这是我想要的 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 吗?还有其他方法可以编写此查询吗?

谢谢,珍妮

4

1 回答 1

5

不要使用匿名类型:

select new { p.ClearinghouseKey })

应该

select p.ClearinghouseKey)

还可以考虑使用 Any 而不是 Contains(我还没有理由选择一个而不是另一个)。

where innerQuery.Any(i => i == o.ClearinghouseKey)
于 2009-01-11T02:33:43.023 回答