Get item page number

I have 10,000 items in a table that display 20 items per page on the client side (items can be further filtered)

I need to find an element among all the elements. Then I need to get the page number where the item is located and go to this page on the client and select it

My previous question is Get the item      index (rownum) .

But I did not receive an answer to this.

Perhaps there is another way to find the page number where the element is located without getting all the table data?

I am using Linq for Nhibernate, Database - Oracle.

Edit: Thanks for the answers, but it's not that simple.

Example:

In the db table I have

 ID          NAME 
 1           Item1 
 2           
 3
 4
 5
 20
 31
 .....        ....
 5000

On the client side, I have filtered data

query = query.Where(...).Where(...).Where(...).OrderBy(...)

and got the result

 ID                                         ROW_NUM_IN_QUERY
 4                                          1
 300                                        2
 2                                          3
 31                                         4
 .....        ....
 402                                        50
 800                                        51

ID ,

rownum SQL. Linq NHibernate . IndexOf RowNumber .

:

var indexed = myDataSource.Select( (x,n) => new { Value = x, RowNumber = n } );

Not suported exception during execute query
+3
3

, Nhibernate Linq.

.

- , .

.

+1

, , . , ; .

, , , - :

var someItem = queryToFetchIndividualItem;

var indexOfItem = table.OrderBy(item => item.CreatedDate)
//any other filtering provided on your query goes here, i.e. other where statements
.Where(item => item.CreateDate < someItem.CreatedDate)
.Count()

"", - :

var indexOfItem = table.OrderBy(item => item.Title)
//any other filtering provided on your query goes here, i.e. other where statements
.Where(item => item.Title < someItem.Title)
.Count()

, . , , . , .

+3

select (http://msdn.microsoft.com/en-us/library/bb534869.aspx):

var indexed = myDataSource.Select( (x,n) => new { Value = x, RowNumber = n } );

, . :

var specificRecord = indexed.FirstOrDefault( x => x.Value.Key == "SomeKey" );

Assuming it doesn't return null(i.e. your key was found), you can get it on the page using simple math:

var page = (int)Math.Floor( (double)specificRecord.RowNumber / pageSize );

Note : you will need to test this method to see if it is being processed in the database, or if you need to take ten thousand records into memory; I tested it without a database, so it may not be very efficient. If this does not work, I recommend creating a stored procedure in your database that returns the line and page number.

+2
source

All Articles