开发者

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜