More in this section
Forums / Suggestions / Module Builder Code reference - Get Collection add Order by example line

Module Builder Code reference - Get Collection add Order by example line

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
1 posts, 0 answered
  1. Markus
    Markus avatar
    2763 posts
    Registered:
    25 Nov 2005
    22 Aug 2012
    Link to this post
    First of all - the module builder is great and the code reference such a huge help.

    However I did as struggle to get an orderby working.

    Original what the codereference shows.
    // Demonstrates how a collection of Quicklinks can be retrieved
    public IQueryable<DynamicContent> RetrieveCollectionOfQuicklinks()
    {
        DynamicModuleManager dynamicModuleManager = DynamicModuleManager.GetManager();
        Type quicklinkType = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Quicklinks.Quicklink");
        CreateQuicklinkItem(dynamicModuleManager, quicklinkType);
                  
        // This is how we get the collection of Quicklink items
        var myCollection = dynamicModuleManager.GetDataItems(quicklinkType);
        // At this point myCollection contains the items from type quicklinkType
        return myCollection;
    }

    a) I think one line should be modified or you get double entries if I am not mistaken.

    var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live)

    b) I did try to have some stuff sorted by a sort value I had added as integer. Dumb as I am I started with.

    var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy("Sortvalue"));

    Then support thought it should be. Which led to an error

    var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy(i => i.GetValue("Sortvalue"));

    CORRECT working was

    adding ' using Telerik.OpenAccess' and modify the line to 

    var myCollection = dynamicModuleManager.GetDataItems(quicklinkType).Where(item => item.Status == ContentLifecycleStatus.Live).OrderBy(i => i.FieldValue<decimal>("Sortvalue"));

    So maybe the order by is a common task that could somehow be implemented as a examples string. Could be commented.

    Thanks again for the support

    Markus




1 posts, 0 answered