如何在Entity Framework中实现'in'子句?

时间:2014-01-13 13:35:00

标签: sql entity-framework

我有以下查询

select distinct X.* from X
inner join Y on X.ID = Y.ID1
inner join Z on Y.ID= Z.ID2
where X.param = 1 and Z.param in (1,2)

到目前为止,我已经实现了X.param上的连接和where子句,但我正在努力研究Z.param的in子句。 id列表由List

类型的listofids提供
entities.X
.Join(entities.Y, t1 => t1.ID, t2 => t2.ID1, (t1, t2) => new { X= t1, Y= t2 })
.Join(entities.Z, t => t.Y.ID, t3 => t3.ID2, (t, t3) => new { X= t.X, Y= t.Y, Z= t3 })
.Select(d => d.X).Distinct().Where(x1 => x1.param == 1)

添加以下内容无效

Any(d1 => d1.Z.param.Contains(listofids))

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

您需要撤销Contains

Any(d1 => listofids.Contains(d1.Z.param))