Get row number

Posts   
 
    
tnewcome
User
Posts: 2
Joined: 12-Feb-2010
# Posted on: 12-Feb-2010 16:39:38   

This is probably very simple, but its been hard for me to find the answer frowning ...
Here's the deal - I have a paged result set of data. I am using paging via LLBLGen - and it works great: adapter.FetchEntityCollection(threadPosts, filter, 0, sortExpression, pageNumber, pageSize);

Now here is my question. I know the primary key (id field) of an entity that gets returned in the overall result set. However, I do not know what pageNumber that entity occurs on.

I can determine the row number that the result would be on via a common table expression in SQL & then use the row number & my pageSize to determine what page # that result would appear on:

WITH ExpressionSet AS (
SELECT ROW_NUMBER() OVER (ORDER BY CreatedDate DESC) AS RowNum,
* FROM SomeChildTable WHERE SomeParentID = @SomeParentID )

SELECT RowNum FROM ExpressionSet WHERE SomeChildTableId = @MyKnownID

However, I have not been able to figure out how to do a similiar thing with LLBLGen. Surely this is a common issue - can someone point me in the right direction?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 12-Feb-2010 19:08:02   

Here is a similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8314 Hope that helps you.

David Elizondo | LLBLGen Support Team
tnewcome
User
Posts: 2
Joined: 12-Feb-2010
# Posted on: 12-Feb-2010 19:29:17   

Thank you for the response. That link doesn't seem to be active anymore? I click it but it takes me back to the home page.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Feb-2010 07:25:21   

Sorry, I linked to a private thread.

So, how your main query looks like? (EntityCollection or DynamicList?) I ask this because I think there're two options:

  1. Inject kind of expression in the main query
  2. Fetch the query with row numbers in one shot with Derived Tables. Something like:
SELECT  
    C2.RowNum,  
FROM  
    Sales.Customer C1 INNER JOIN    
        (SELECT 
            ROW_NUMBER() OVER (ORDER BY AccountNumber DESC) AS RowNum, 
            CustomerID
        FROM 
            Sales.Customer 
        WHERE TerritoryID = 4
        ) C2 ON C1.CustomerID = C2.CustomerID
WHERE 
    AccountNumber = 'AW00029272'
David Elizondo | LLBLGen Support Team