首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

求教一个Linq里查询的有关问题

2012-01-16 
求教一个Linq里查询的问题sql里的 select * from table where id in (1,2) 在LinQ里怎么写呀LinQ里有

求教一个Linq里查询的问题
sql里的 select * from table where id in ('1','2') 在LinQ里怎么写呀
LinQ里有没有 in 这种方式呀?

[解决办法]
如果只有两个,那就:
var re = from t in table 
where t.id == "1"
|| t.id == "2"
select t;

如果很多,考虑用数组:
string[] idArr = {"1","2","3",....};
var re = from t in table 
where idArr.contains(t.id)
select t;
[解决办法]

探讨
sql里的 select * from table where id in ('1','2') 在LinQ里怎么写呀
LinQ里有没有 in 这种方式呀?

[解决办法]
如果很多,考虑用数组:
string[] idArr = {"1","2","3",....};
var re = from t in table
where idArr.contains(t.id)
select t; //我一般用字符串

热点排行