If you request DbSet directly, you can use Take and Skip and it will actually do the swap on the database server (these method calls translate to SQL). Thus, this works as expected:
Beware that the swap navigation properties on a loaded object do not work as follows:
var blog = context.Blogs.First(); // Lazy loading always loads all related entries and executes ordering and // paging through Linq-to-objects! var entires = blog.BlogEntries.OrderBy(e => e.Date).Skip(10).Take(10);
If you want to get paging for the navigation property, you must use explicit loading
var blog = context.Blogs.First(); var dbEntry = context.Entry(blog); // This is the way to use Linq-to-entities on navigation property and // load only subset of related entities var entries = dbEntry.Collection(b => b.BlogEntries) .Query() .OrderBy(e => e.Date) .Skip(10) .Take(10) .Load();
Ladislav Mrnka
source share