0

I am trying to mimic an IN() clause commonly used in SQL and use it in my LINQ statement. I see that there is an overload for Contains() that takes an IEnumerable collection. I have tried passing in ILIST and Dictionary but neither is correct. How do I accomplish this?

Thanks, much appreciated.

SQL

select oec.OnlineEducationCourseId, oec.CourseTitle,COUNT(oec.CourseTitle) as CourseCount from OnlineEducationRegistration as oer join OnlineEducationCourse oec on oec.OnlineEducationCourseId = oer.OnlineEducationCourseId where oer.ClubId IN('K20','B67','P89') and DateCompleted between '2013-01-01' and '2014-01-01' group by oec.CourseTitle,oec.OnlineEducationCourseId 

Same SQL query in LINQ

var r = (from oer in db.OnlineEducationRegistrations join oec in db.OnlineEducationCourses on oer.OnlineEducationCourseId equals oec.OnlineEducationCourseId where (oer.ClubId.Contains(some IEnumerable collection here) && oer.DateCompleted >= start.Date && oer.DateCompleted <= end.Date) group new { oec, oer } by new { oec.CourseTitle, oec.OnlineEducationCourseId }).ToList(); 
3
  • This where (oer.ClubId.Contains(some IEnumerable collection here) should be other way round like where (SomeIEnumerable.Contains(oer.ClubId)) Commented Sep 26, 2014 at 19:10
  • What do you mean, "but neither is correct"? Doesn't it work (if not, please be more specific and post a code example that reproduces the issue, not just "some IEnumerable collection here"), or do you simply dislike your solution somehow? Commented Sep 26, 2014 at 19:11
  • @stakx Sorry for leaving out some important details. The error was caused by the value I was giving to Contains(). I was giving it a collection when it really needed a single value Commented Sep 29, 2014 at 11:48

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.