Raghubar
Raghubar

Reputation: 2788

Sql IN Clause equivalent in Linq

I want to use sql in cluase in linq for that i have tried contains but its showing error. My Code is..

 var allId = new int[] { 31, 32, 33 };
 var libraryList = from c in db.COURSELIBRARies
                   join cc in db.COURSECATEGORYTAGGINGs on c.LIBITEMID equals cc.COURSEID
                   where allId.Contains(cc.CATEGORYID) // here error is showing.
                   select new Library { Id = c.LIBITEMID, Name = c.GROUPNAME, Desc = c.DESCRIPTION, logo = c.LOGO, CategoryId = cc.CATEGORYID };

Error is :

'int[]' does not contain a definition for 'Contains' and the best extension method overload 'System.Linq.Queryable.Contains<TSource>(System.Linq.IQueryable<TSource>, TSource)' has some invalid arguments

Instance argument: cannot convert from 'int[]' to 'System.Linq.IQueryable<int?>'

Upvotes: 1

Views: 1411

Answers (1)

JanR
JanR

Reputation: 6132

Have you included;

using System.Linq;

?

Another possible cause would be that the value you are passing into Contains() is not an INT. Try casting it: where allId.Contains((int)cc.CATEGORYID)

Upvotes: 1

Related Questions