首页 新闻 会员 周边

Linq to Sql 查询指定数据

0
悬赏园豆:10 [已解决问题] 解决于 2008-07-21 18:14
Orders表 <BR>OrderID OrderName <BR>1&nbsp; &nbsp; &nbsp; aaaa <BR>2&nbsp; &nbsp; &nbsp; bbbb <BR>3&nbsp; &nbsp; &nbsp; cccc <BR>4&nbsp; &nbsp; &nbsp; dddd <BR>5&nbsp; &nbsp; &nbsp; eeee <BR>6&nbsp; &nbsp; &nbsp; ffff <BR><BR>有一个int数组 <BR>var a=new int[]{2,5,6}; <BR><BR>a里的值对应OrderID <BR><BR>现在我想根据a数组里的编号值 查询这些编号的信息 <BR><BR>有什么最简单的Linq语句 不想用foreach <BR><BR>谢谢!
hekai的主页 hekai | 初学一级 | 园豆:85
提问于:2008-07-20 09:35
< >
分享
最佳答案
0
linq 也得foreach啊.把简单问题复杂化了吧.
Jerry Qian | 初学一级 |园豆:19 | 2008-07-20 12:52
其他回答(1)
0
例:select * from table where name in(a,b,c,d); 中的a,b,c,d写成 pulbic class WhereName { public string name{ get; set; } } List<WhereName> ListWhere = new List<WhereName>(); ListWhere .Add(new WhereName{ name='a'}); ListWhere .Add(new WhereName{ name='b'}); ListWhere .Add(new WhereName{ name='c'}); 在linq中 var r = from p in table from n in ListWhere where p.name == n.name select p; 当然这只是我的想法,都是手打的,里面有可能有语法错误!
petersun | 园豆:215 (菜鸟二级) | 2008-07-21 11:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册