开发者

Transform LINQ IQueryable into a paged IQueryable using LINQ to NHibernate

I wanna do something like that

    public IQuerya开发者_JAVA技巧ble GetPaged<TSource>(IQueryable<TSource> query, int startIndex, int pageSize)
    {
        return GetSession()
          .Linq<TSource>()
          .UseQuery(query)
          .Take(pageSize)
          .Skip(startIndex);
    }

So you can put any IQuerable statement and "it becomes paged" or it will be paged.

I am using LINQ to NHibernate. I hope you get it, sry for this bad english :o

edit: Maybe my approach is the wrong one, is it?


This is copied from working code:

public static class QueryableExtensions
{   
    public static IQueryable<T> Paged<T>(this IQueryable<T> source, int page,
                                                                    int pageSize)
    {
        return source
          .Skip((page - 1) * pageSize)
          .Take(pageSize);
    }
}


return query.skip(startIndex).take(pageSize);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜