0

I have the following query

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)

So far I have the joins and the where clause on the X.param implemented but I'm struggling on the in clause of Z.param. The list of id's is supplied by a listofids of type List

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)

Adding the following does not work

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

Any ideas?

1
  • Removed the Any and added the 'in' clause to the 'Where' clause 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 }) .Where(x1 => x1.X.param == 1 && listofids.Contains(x1.Z.param)).Select(d => d.X).Distinct() Commented Jan 13, 2014 at 14:02

1 Answer 1

2

You need to reverse the Contains:

Any(d1 => listofids.Contains(d1.Z.param))
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the correct usage. But doing so know results in a compile error Cannot implicitly convert type 'bool' to 'System.Collections.Generic.IEnumerable<>'
I assume listofids is a List<int>? Is d1.Z.param an int?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.