How do you generate a WHERE...IN clause using LINQ2SQL?
Going backwards from SQL to LINQ2SQL is sometimes quite simple. The following statement
SELECT user FROM users WHERE lastname='jones'
tran开发者_开发知识库slates fairly easily into
from u in users where u.lastname='jones' select u
But how do you get the following SQL generated?
SELECT user FROM users WHERE lastname IN ('jones', 'anderson')
I had to do a bit of searching to find this, and thought it might be useful to others.
List<string> names = new List<string>() { "jones", "anderson" };
from u in users where names.Contains(u.lastname) select u
精彩评论