c# - Paginated search results with LINQ to SQL -
What is the best pattern to get paged results with SQL from LINQ?
I have the following scenario:
Suppose to find the item table description . I can do it easily:
Public IQueryable & lt; Items & gt; FindItemsByDescription (string description) {_dc.Items Return items from items in where. Description. Included (details); } Now, what would be the best way to endorse this result set?
- Can I limit this question to do this to know the size of the result set before the count query and then what I want? I feel that this is the way to go.
- Should I follow the full query, count the array with size and return only a paused subset from this array? I think it will be a big waste of time if the result is huge ... or from LINQ to SQL doing some magic here?
Is LINQ to SQL normal pattern to perform this action?
Edit: I should clarify a small thing I know about ways to take and leave. However, before using Take and Skip , how should I get the total count of the results that will retrieve the query?
Pattern is very simple for paging: The use of the Skip () and Tech () extension methods is as follows :
Public IQueryable & lt; Items & gt; FindItemsByDescription (string description, int page index, int pagesize) Return items from items to _dc.Items where items Includes (details). Skip ((page index - 1) * pages). Take (pageSize); Use the calculation () method to get the total count: Update _dc.It items from items where items Includes (Details) .ount (); Int Numberoffiffage = (Int) (Total Count / PageSize);
Depending on how you are going to the record of the display, you can use numbers to display a navigation bar with "Page X of Y" ... 10 Page 1 of, etc. .
Comments
Post a Comment