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

是这么写吗? Library.Take(count).Where(a => a.Status==status)
刚开始用不久,是不是下边这么写?

我要查询 Library 中,状态为0的,10条数据,按照PubDate时间,取时间靠前边的



 return db.Library.Take(count).Where(a => a.Status==status).OrderBy(a => a.PubDate).ToList();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="count">需要的文档数量</param>
        /// <param name="status">需要文档的状态</param>
        /// <returns></returns>
        public static List<Library> GetUploadBooks(int count=10,int status = 0)
        {
            using (var db = new WEBVODEntities())
            {
                return db.Library.Take(count).Where(a => a.Status==status).OrderBy(a => a.PubDate).ToList();
            }
 
        }

------解决方案--------------------
自己运行看看结果
------解决方案--------------------
return db.Library.Where(a => a.Status==status).OrderBy(a => a.PubDate).Take(count).ToList()
------解决方案--------------------
你正好搞反了,先WHERE过滤再排序,最后TAKE取数据