Using SorterToUse with LlblGenProDataSource

Posts   
 
    
ADF1969
User
Posts: 37
Joined: 28-Mar-2006
# Posted on: 07-Mar-2007 20:06:22   

I have a page that I created that has the following configuration:


            poDataSrc = New LLBLGenProDataSource()
            With poDataSrc
                .ID = pc_sDataSrcId
                .LivePersistence = True
                .CacheLocation = DataSourceCacheLocation.Session
                .DataContainerType = DataSourceDataContainerType.EntityCollection
                .EntityCollection = Me.GetDataFromBuffer()
                .EnablePaging = True                
                .SortingMode = DataSourceSortingMode.ServerSide

            End With

Later on, in the Load event, I do the following:


                ' This gets the correct "RelationsCollection" for this Form.
        Dim relationsToUse As New RelationCollection
        relationsToUse = DataObjectLoader.GetEntityRelations(Me.CurrentFormName)

        With poDataSrc
            Dim oFilter As New PredicateExpression
            Dim oCustomFilter As PredicateExpression = _
             Me.GMod_BuildCustomWhereClause()
            Dim oContextFilter As PredicateExpression = _
             Me.GMod_BuildContextWhereClause()

            With oFilter
                ' Add the GridWhereClause if it exists..
                If oWhere IsNot Nothing Then
                    logger.Info("Set GMod Predicate = '{0}'", oWhere.WhereClause)
                    .Add(oWhere)
                End If

                ' Add any custom filter, if it exists...
                If (oCustomFilter IsNot Nothing) Then
                    .Add(oCustomFilter)
                End If

                ' Add any Context filter, if it exists
                If (oContextFilter IsNot Nothing) AndAlso (oContextFilter.Count > 0) Then
                    .Add(oContextFilter)
                End If
            End With

            If oFilter.Count > 0 Then
                logger.Trace("[{0}] > oFilter = '{1}'", Me.FormName, Divix.Data2.LgpUtil.GetPredicateQueryText(oFilter))
                .FilterToUse = oFilter
            Else
                .FilterToUse = Nothing
            End If

            ' Add Relations
            .RelationsToUse = relationsToUse

' This is put here for testing to see what happens when the "SorterToUse" is changed in a PostBack.
            If Not Me.IsPostBack Then
                Dim oSorter As New SortExpression
                With oSorter
                    .Add(New SortClause(HelperClasses.AccountFields.QbcompanyName, SortOperator.Ascending))
                End With
                .SorterToUse = oSorter
            Else
                Dim oSorter As New SortExpression
                With oSorter
                    .Add(New SortClause(HelperClasses.LocationFields.Description, SortOperator.Ascending))
                End With
                .SorterToUse = oSorter
            End If
            .Refetch = True
            '           
        End With


Now here is where things are odd.

Aside from sorting everything works flawlessly on first page load. On First Page Load it sets the sort of the "Grid" that is bound to this DataSource correctly, all is well. On 2nd page load, sorting is not functioning as I expect (I expected it to SORT by LOCATION.Description...according to the Tracing output it creates a SELECT with NO "ORDER BY" clause at all.

So my question is this: How can I change the "sort" of DataSource and have that get reflected in the DataSource that is fetched? Is there some special voodoo going on that doesn't cause the "ORDER BY" to be persisted because I have "LivePersistance=True"? I realize that changing the "Sort" will force it to re-fetch the dataset, which is fine, but it should still function (IMHO).

I'm fairly certain I could probably make it ALL work if I turned LivePersistance=False but I really don't want to have to do that (I may have to at some point, but I almost have this all working and setting that to "False" will require me to re-do all the binding logic that is currently working quite well...)

Thanks.

Andrew.

EDIT: Designer Ver: 2.0.0.0 Final ORMSupportClasses Ver: 2.0.07.0105 Type: SelfServicing DB: SQL2000 Framework Ver: ASP.NET 2.0

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Mar-2007 05:28:05   

Are you sorting on fields mapped from related fields? If yes -> it won't work on Server-Side Sorting.

Quoted from the manual:

Server-side sorting only uses EntityField objects, so if the entity has a field which isn't a field mapped onto a table/view field, it's ignored in the server-side sorting actions because it's not part of the query send to the database. This is also true for fields mapped onto related fields. In these situations, use client-side sorting.

ADF1969
User
Posts: 37
Joined: 28-Mar-2006
# Posted on: 09-Mar-2007 02:06:59   

No, I was not sorting on a Calculated Field.

The issue was related to a Telerik RadGrid - it appears if LivePersistance = True then making modifcations to the SorterToUse get "clobbered" by the RadGrid.

To be honest, I wish I could find more docs on what happens with a DataSource but there isn't much out there...so I have no idea how the "FieldName" in the RadGrid gets converted to a "EntityField" in the LGP side of things.

I ended up just setting LivePersistance = False and then wiring my own code and that is working perfect.

Thanks for the feedback on my question.

Andrew.