Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Robert Brown 18 posts 38 karma points
    Jul 08, 2014 @ 15:58
    Robert Brown
    0

    How do I sortby or groupby more than one field?

    I am using this code to get contour records:

     foreach (dynamic record in 

               Umbraco.Forms.Mvc.DynamicObjects.Library.GetApprovedRecordsFromPage(@Model.Id).OrderBy("Created desc"))

     {  etc....

    This works fine,  but what i want to do is a group by and then an order by operation to create linked comments.

    My comment form has a hidden field that contains the recordId of the parent comment. I would like to group by parent recordid and then sort by Created.

    Is this possible?

    Bob

  • Robert Brown 18 posts 38 karma points
    Aug 06, 2014 @ 21:32
    Robert Brown
    0

    Anyone know of orderby or groupby syntax for more than one field using a built-in method such as GetApprovedRecordsFromPage or  RecordStorage getrecord or getallrecords?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Aug 06, 2014 @ 22:04
    Dennis Aaen
    0

    Hi Rob,

    I thin that you should be able to orderby for more than one field using syntax this syntax. Try to see the documentation here: http://umbraco.com/follow-us/blog-archive/2011/3/1/umbraco-razor-feature-walkthrough-%E2%80%93-part-4

    In shorthand you should be able to do something like this:

    @foreach(dynamic record in Umbraco.Forms.Mvc.DynamicObjects.Library.GetApprovedRecordsFromPage(@Model.Id).OrderBy("Created, Name desc")){
     
    }

    And longhand syntax looks like this:

    @foreach(dynamic record in Umbraco.Forms.Mvc.DynamicObjects.Library.GetApprovedRecordsFromPage(@Model.Id).OrderBy("Created desc").OrderBy("Name desc")){
     
    }

    Hope this helps,

    /Dennis

  • Robert Brown 18 posts 38 karma points
    Aug 07, 2014 @ 18:42
    Robert Brown
    0

    Thanks for your reply Dennis. Your first exaple give a linq error, the second example deos work but not in the way I expect. What I need is a GroupBy and then a SortBy within the group. I think dynamicobjects does not support GroupBy.

    I am going to try record storage an see if that will work.

     

    Bob

Please Sign in or register to post replies

Write your reply to:

Draft