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

linq多ID查询,这句话查询语句应该如何写

2014-01-13 
linq多ID查询,这句话查询语句应该怎么写? IQueryableNewsInfo queryable (from c in this.db.NewsInfo

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);

热点排行