Collection Sorting Again

Posts   
 
    
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 06-Dec-2004 20:51:15   

I just can't seem to get collection sorting down. help from anyone would be greatly appriciated.

The following returns with the PageTemplates correctly sorted by startdate

        Dim MasterTemplateMap As CMS.EntityClasses.MasterTemplateMapEntity
        Dim sorter As ISortExpression = New SortExpression(CMS.FactoryClasses.SortClauseFactory.Create(CMS.MasterTemplateFieldIndex.StartDate, SortOperator.Descending))
        MasterTemplateMap = New CMS.EntityClasses.MasterTemplateMapEntity(1)
        MasterTemplateMap.SetCollectionParametersMasterTemplate(10, sorter)

However why does the following not return with the correct sorting. I'm trying to access the MasterTemplateMap's MasterTemplate collection from it's parent 'PageMap'

        Dim sorter As ISortExpression = New SortExpression(CMS.FactoryClasses.SortClauseFactory.Create(CMS.MasterTemplateFieldIndex.StartDate, SortOperator.Descending))
        Dim PageMap As New CMS.EntityClasses.PageMapEntity
        PageMap.MasterTemplateMap.SetCollectionParametersMasterTemplate(0, sorter)
        PageMap.FetchUsingPK(1)

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 06-Dec-2004 21:14:39   

Samuel wrote:

However why does the following not return with the correct sorting. I'm trying to access the MasterTemplateMap's MasterTemplate collection from it's parent 'PageMap'

        Dim sorter As ISortExpression = New SortExpression(CMS.FactoryClasses.SortClauseFactory.Create(CMS.MasterTemplateFieldIndex.StartDate, SortOperator.Descending))

        Dim PageMap As New CMS.EntityClasses.PageMapEntity
        PageMap.MasterTemplateMap.SetCollectionParametersMasterTemplate(0, sorter)
        PageMap.FetchUsingPK(1)

Thanks

Your code sets the sorter for the MasterTemplateMap.MasterTemplate collection. Doesn't it get sorted when yuo fetch it, like: MasterTemplateCollection templates = PageMap.MasterTemplateMap.MasterTemplate; ?

Frans Bouma | Lead developer LLBLGen Pro
Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 06-Dec-2004 21:32:50   

Nope here is the full block of code

        Dim sorter As ISortExpression = New SortExpression(CMS.FactoryClasses.SortClauseFactory.Create(CMS.MasterTemplateFieldIndex.StartDate, SortOperator.Descending))
        Dim PageMap As New CMS.EntityClasses.PageMapEntity
        PageMap.MasterTemplateMap.SetCollectionParametersMasterTemplate(0, sorter)
        PageMap.FetchUsingPK(1)
        Dim MasterTemplates As CMS.CollectionClasses.MasterTemplateCollection
        MasterTemplates = PageMap.MasterTemplateMap.MasterTemplate
        UT.WriteLine(MasterTemplates(0).Name & "  " & MasterTemplates(0).StartDate)
        UT.WriteLine(MasterTemplates(1).Name & "  " & MasterTemplates(1).StartDate)

The output never changes when I flip ascending vs descending ?? It's always Template1 12/2/2004 Template2 12/5/2004

If I can just get past this sorting thing I'll be good to go (maybe wink )

Samuel
User
Posts: 9
Joined: 04-Dec-2004
# Posted on: 06-Dec-2004 21:48:47   

Ok it works now so I have call SetCollectionParameters after I've called fetchUsingPK?

Is this correct ?

Thank you very much for the great support smile

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 07-Dec-2004 11:30:22   

Samuel wrote:

Ok it works now so I have call SetCollectionParameters after I've called fetchUsingPK?

Is this correct ?

It sets properties of the member collections. These properties do not have any effect if the collections are already fetched, so it doesn't matter if you call FetchUsingPK or not, it does matter if you've touched the collection properties before setting the SetCollectionParameters call simple_smile

Frans Bouma | Lead developer LLBLGen Pro