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

linq多ID查询,这句话查询语句应该怎么写?

 IQueryable<NewsInfo> queryable = (from c in this.db.NewsInfo
                                              where c.SmallId == 9 //这里我要查询:9,10,11,12,13多个ID,怎么写?                                              orderby c.id descending
                                              select c).Take<NewsInfo>(itop);


where c.SmallId == 9 //这里我要查询:9,10,11,12,13多个ID,怎么写?   

------解决方案--------------------
定义一个id数组,判断  数组.Contans(c.SmallId)
------解决方案--------------------
IQueryable<NewsInfo> queryable = (from c in this.db.NewsInfo
                                 where "9,10,11,12,13".Split(',').Contains(c.SmallId)                                           orderby c.id descending
                                              select c).Take<NewsInfo>(itop);
.

参考:http://blog.csdn.net/q107770540/article/details/5387946
------解决方案--------------------

 IQueryable<NewsInfo> queryable = (from c in this.db.NewsInfo
                          where new int[] { 9,10,11,12,13 }.Contains(dt.Field<Int32>("SmallId ")) 
                          orderby c.id descending
                          select c).Take<NewsInfo>(itop);

------解决方案--------------------

IQueryable<NewsInfo> queryable = this.db.NewsInfo.Where(c => new int[] { 9, 10, 11, 12, 13 }.Contains(c.SmallId)).Take<NewsInfo>(itop);