Sort clause stops paging

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 13-Jun-2005 15:44:40   

Hi,

I have..


ResultsetFields fields = new ResultsetFields(1);
fields.DefineField(PhotoGalleryFieldIndex.PhotoId, 0, "PhotoId");

RelationPredicateBucket bucket = new RelationPredicateBucket();
bucket.Relations.Add(PhotoGalleryEntity.Relations.PhotoGalleryOrderedListEntityUsingPhotoId);

SortExpression sortExpression = new SortExpression();
sortExpression.Add(SortClauseFactory.Create(PhotoGalleryOrderedListFieldIndex.Ordinal, SortOperator.Ascending));

DataAccessAdapter adapter = new DataAccessAdapter();
DataTable table = new DataTable();

int num2 = adapter.GetDbCount(fields, bucket, null, false);

adapter.FetchTypedList(fields, table, bucket, 10000, sortExpression, false, null, 1, 21);

If I take out the sort expression, the paging appears to work ok. If I add it in then all the results are returned regardless of the paging parameters.

Should this be happening?

Cheers,

Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jun-2005 16:25:48   

On which database flavor do you execute this ?

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 13-Jun-2005 17:06:50   

SQL Server 2000

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 13-Jun-2005 21:36:16   

As you don't want duplicates, you have to specify the sort field in the select list, i.e. you have to add the field PhotoGalleryOrderedListFieldIndex.Ordinal to the resultsetfields.

This is because DISTINCT can't be in a query where an ORDER BY is specified with a field NOT in the select list (as you're trying to do). The code then switches to client-side duplicate filtering. This isn't possible for datatable fetches, only on entity fetches. Paging is then switched off as well, as duplicates have to be filtered out, and paging is then not possible (as the first page for example can be solely made of duplicates).

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 14-Jun-2005 15:16:56   

That fixed it. Thanks very much for your help.