开发者

How do you generate a WHERE...IN clause using LINQ2SQL?

开发者 https://www.devze.com 2022-12-18 22:28 出处:网络
Going backwards from SQL to LINQ2SQL is sometimes quite simple. The following statement SELECT user FROM users WHERE lastname=\'jones\'

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

精彩评论

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