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

Linq To Entity 分页问题
C# code

      public static List<User> PageUser(int pageIndex, int pageSize, out int count)
        {
            var query = (from User in entities.User
                         orderby User.Id descending
                         select User).Skip((pageIndex-1)*pageSize).Take(pageSize);
            
            count = entities.User.Count();
            return query.ToList();

        }



这个分页需要每个BLL类里面写一次,有没有通用的分页方法啊,小弟菜鸟,请多指教

------解决方案--------------------
C# code
public List<TEntity> Page<TEntity>(string keys, int pageIndex, int pageSize, out int count) where TEntity : EntityObject
{
    using (var ctx = new XXXEntities())
    {
        var es = ctx.CreateObjectSet<TEntity>();
        count = es.Count();
        var query = es.OrderBy(keys).Skip((pageIndex - 1) * pageSize).Take(pageSize); 
        return query.ToList();
    }
}