cancel
Showing results for 
Search instead for 
Did you mean: 

Implementing paging with entity framework?

Former Member
3,985

I'm coming over from the MSSQL world and have gotten used to things like Skip to help with paging.

From what I can gather Skip isn't supported with the iSqlAnywhere provider so the only way I can think of off the top of my head are to use my filtered IQueryable to bring back primary keys and perform a skip take on them in memory and then do a contains to bring back the actual data I need.

To me this seems kind of hacky and I would definitely appreciate any other thoughts on the matter.

Writing SQL statements directly is not an option.

Here is an example of what I'd be doing.

IQueryable<foo> bar =  someAlreadyFilteredQueryable;
var barIds = bar.Select(b=>b.Id).ToList();
var finalIds = barIds.Skip(pageNum * pageSize).Take(pageSize);
var result =  someAlreadyFilteredQueryable.Where(s=> finalIds.Contains(s.Id)).ToList();

Like I said it seems hacky considering I can just do someAlreadyFilteredQueryable.Skip(pageNum * pageSize).Take(pageSize).ToList() with MSSQL.

Edit: It appears the query generated behind the scenes uses the ALL keyword that isn't supported in the version of sybase I'm hitting.

TLDR - You need to be on V12 to use Skip

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

Skip is supported. I use it in my code all the time.

Edit:

For example, here's some code from my program that performs a paged search of one of the tables in our database:

noPages = (int) ( noMatchingEntries / pageSize );
if ( noMatchingEntries % pageSize != 0 )
    noPages++;

if ( pageNo > 0 ) {
    query = query.Skip( pageNo * pageSize );
}

query = query.Take( pageSize );
Former Member
0 Kudos

Can you give me an example? What version are you running?

Every time I attempt to do so I get a syntax error - 'Syntax error near 'ALL' on line 6'

reimer_pods
Participant
0 Kudos

What SA version are you using?

Former Member
0 Kudos

It appears this particular DB is on 11.0.1.2506

Former Member
0 Kudos

We're using SA 12.0.1.3895. We're also using the same version of the SA ADO.NET / Entity Framework driver. See the edits to my answer for an example.

Answers (0)