我有以下查詢如何在實體框架中實現'in'子句?
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的條款掙扎的。 ID的列表是按類型列表
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)
添加以下的listofids提供不起作用
Any(d1 => d1.Z.param.Contains(listofids))
任何想法?
刪除了任何和添加的 '中' 子句到 '哪裏' 子句entities.X 。加入(entities.Y中,t1 => t1.ID ,t2 => t2.ID1,(t1,t2)=> new {X = t1,Y = t2}) .Join(entities.Z,t => tYID,t3 => t3.ID2, (x1 => x1.X.param == 1 && listofids.Contains(x1.Z.param))。Select(d(t3)=> new {X = tX,Y = tY,Z = t3}) 。 => dX).Distinct() – Geoffrey