日期:2014-05-20  浏览次数:20850 次

Sqlserver查询方式翻译为Linq
select * from sys_Tree where id in (1,2,3)
这样的查询语句在linq中怎样写那!

------解决方案--------------------
C# code

int[] intArray = new int [] { 1, 2, 3 };
var result = from c in sys_Tree
                 where intArray .Contains(c.id)
                 select c;

------解决方案--------------------
int[] intArray = new int [] { 1, 2, 3 };
var result = from c in sys_Tree
where intArray .Contains(c.id)
select c;

------解决方案--------------------
 
var result = from c in sys_Tree
where new int[]{ 1, 2, 3 }.Contains(c.id)
select c;

OR:

var result =sys_Tree.Where(c=>int[]{ 1, 2, 3 }.Contains(c.id));

------解决方案--------------------
用ls的第二种lambda表达式,看起来舒服
------解决方案--------------------
http://blog.csdn.net/q107770540/article/details/5387946
------解决方案--------------------
from u in sys_Tree 
where u.id.Contains(1,2,3)
select u
------解决方案--------------------
弱弱的表达下,至今我都不懂什么是lambda表达式,但我写的linq跟楼上所写的一样,不知道是也不是