0

I need to apply paging logic to this Query. How can i do that?

My query is as follows,

myresultset = from req in myreqTable
              join streq in myStreqTable on req.ID.ToString() equals new SPFieldLookupValue( Convert.ToString( streq[FormID] ) ).LookupValue
              where (filter(req) && filter1(streq))
              join plnts in plantDetails on Convert.ToString( streq[RequestID) equals Convert.ToString(plnts[RequestID]) into mySet
              from s in mySet.DefaultIfEmpty()
              select new Mytable() {
                  FormID = Convert.ToString(streq[FormID]),
                  RequestID = Convert.ToString(streq[RequestID])
              };
Dai
  • 141,631
  • 28
  • 261
  • 374

3 Answers3

3

Add .Skip( pageSize * pageIndex ).Take( pageSize ); to the end of your query. Note that pageIndex is zero-based (so the first page is 0, the second page is 1 and so on).

However your Linq doesn't look valid to me, and has some syntax errors. Are you sure this is your code as it is in your editor?

Dai
  • 141,631
  • 28
  • 261
  • 374
0

Use Take and Skip methods:

myresults = myresults.Skip((page - 1) * pageSize).Take(pageSize);

I assumed page numeration starts from 1.

MarcinJuraszek
  • 124,003
  • 15
  • 196
  • 263
0
recordsForCurrentPage = myresultset.Skip( recordsPerPage * pageNumber ).Take( recordsPerPage )

This is assuming that your page number starts with 0. Otherwise subtract 1 from pageNumber.

Chris
  • 6,914
  • 5
  • 54
  • 80