read records from database with index using entity framework

Started by
2 comments, last by Nik02 8 years, 5 months ago

hi. im working on a asp webform project. i want to let user see the records like bellow;


<% shop.Models.ShopDataBaseEntities1 sdb = new shop.Models.ShopDataBaseEntities1();
       var query = sdb.customer; %>
    <table class="table table-hover">
        <%foreach (var q in query){ %>
     
        <tr><td><%=q.cellphone %></td><td><%=q.telephone %></td><td><%=q.customerAddress %></td><td><%=q.customerZipCode %></td><td><%=q.customerFamily  %></td><td><%=q.customerName %></td><td><%=q.customerID %></td></tr>
        <%} %>
    </table>

i want to make it to show for example 10 records every page. so the structure that comes to my mind that if my queried records had indexes so i could send the index of records i have shown to next page as url parameter to show the rest of records but the query object hopefully has no index parameter or any int order value.

maybe im doing the job wrong and there is other way to do the job. thanks for your help.

Advertisement
What you're looking for is "pagination", which should be available to LINQ, ASP.NET, and etc...
As fastcall22 said.

More precisely you can apply paging using "skip take". For example:


// things are of type DbSet

var pageSize = 10;
var page = 2; // passed in from view

var pagedResult = things.AsQueryable().Where(thing => thing.IsAccesible).Skip((page - 1) * pageSize).Take(pageSize).ToArray();
Linq supports skip and take, you can modify the "query" to include the operations.

Niko Suni

This topic is closed to new replies.

Advertisement