Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Paging in Entity Framework

In Entity Framework, using LINQ to Entities, database paging is usually done in following manner:

int totalRecords = EntityContext.Context.UserSet.Count; var list     = EntityContext.Context.UserSet                  .Skip(startingRecordNumber)                  .Take(pageSize)                  .ToList(); 

This results in TWO database calls.

Please tell, how to reduce it to ONE database call.

Thank You.

like image 222
dev Avatar asked Jun 26 '09 15:06

dev


People also ask

What is paging in MVC?

mvc is a package for paging and sorting for ASP.NET MVC. PagedList package installs a PagedList collection type and extension methods for IQueryable and IEnumerable collections. Table Data. Open a New Project.

What is paging in C#?

The C# pagination logic is contained in a single Pager class that takes the following constructor arguments: totalItems (required) - the total number of items to be paged. currentPage (optional) - the current active page, defaults to the first page. pageSize (optional) - the number of items per page, defaults to 10.

Does pagination improve performance?

Thanks to pagination, we can split our large dataset into chunks ( or pages ) that we can gradually fetch and display to the user, thus reducing the load on the database. Pagination also solves a lot of performance issues both on the client and server-side!

How do I filter data in Entity Framework?

To filter data, use linq. You can not use Filter property of BindingSource when the underlying list is BindingList<T> ; Only underlying lists that implement the IBindingListView interface support filtering. To remove filter, just set the data source of your binding source to the local storage of your entities again.


1 Answers

Whats wrong with two calls? They are small and quick queries. Databases are designed to support lots of small queries.

A developing a complex solution to do one query for paging isn't going give you much pay off.

like image 169
Casey Burns Avatar answered Oct 09 '22 12:10

Casey Burns