• Advertisement
Sign in to follow this  

read records from database with index using entity framework

This topic is 889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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();

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement