Linq to SQL - How to compare against a collection in the where clause?
Posted
by
Sgraffite
on Stack Overflow
See other posts from Stack Overflow
or by Sgraffite
Published on 2011-01-02T02:51:04Z
Indexed on
2011/01/02
2:53 UTC
Read the original article
Hit count: 171
I'd like to compare against an IEnumerable collection in my where clause. Do I need to manually loop through the collection to pull out the column I want to compare against, or is there a generic way to handle this?
I want something like this:
public IEnumerable<Cookie> GetCookiesForUsers(IEnumerable<User> Users)
{
var cookies = from c in db.Cookies
join uc in db.UserCookies on c.CookieID equals uc.CookieID
join u in db.Users on uc.UserID equals u.UserID
where u.UserID.Equals(Users.UserID)
select c;
return cookies.ToList();
}
I'm used to using the lambda Linq to SQL syntax, but I decided to try the SQLesque syntax since I was using joins this time.
What is a good way to do this?
© Stack Overflow or respective owner