Copied to clipboard

Flag this post as spam?

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


  • organic 108 posts 157 karma points
    Mar 08, 2012 @ 00:43
    organic
    0

    .OrderByDescending returns null

    Umbraco 5.

    If I uncomment out the OrderByDescending line below(and only use one semicolon, of course), I get a null exception at the start of my foreach loop.  Why could this be happening?

        @{
    var rootNode = Model.AncestorContentOrSelf().Last();
    var L1Pages = rootNode.Children()
    .Where(x => x.ContentType.Alias == "navigationItem");
    //.OrderByDescending(x => x.SortOrder);
    }

    @foreach (var L1Page in L1Pages)
    {...}

    I can successfully use OrderByDescending on another template...

    @{
    var sliderItems = Model.DescendantContent()
    .Where(x => x.ContentType.Alias == "sliderItem")
    .OrderByDescending(x => x.SortOrder);
    }

    @foreach (var sliderItem in sliderItems)
    {...}

     

  • organic 108 posts 157 karma points
    Mar 08, 2012 @ 23:46
    organic
    0

    Seems like it has something to do with the bad statement returning an IQueryable(), and the good statement below return IEnumerable(), but I've tried lots of statements and still can't get it to work.

  • organic 108 posts 157 karma points
    Mar 13, 2012 @ 18:51
    organic
    0

    I'm starting to think there is a bug in Umbraco 5 because this is such a simple statement. I have changed it 20 ways, but no luck.  No one else is seeing an error when trying to OrderByDescending?

    NullReferenceException' occurred in Umbraco.Framework.Persistence.NHibernate.DLL

    The statement only works when I remove .OrderByDescending(x => x.SortOrder)

    @inherits RenderViewPage
    @using Umbraco.Cms.Web;

    @{
    var rootNode = Model.AncestorContentOrSelf().Last();
    var L1Pages = rootNode.Children()
    .Where(x => x.ContentType.Alias == "navigationItem")
    .OrderByDescending(x => x.SortOrder);
    }

    @foreach (var L1Page in L1Pages)
    {...}

  • organic 108 posts 157 karma points
    Apr 05, 2012 @ 23:20
    organic
    0

    If I change the previous statement to use AsEnumerable() it will execute without errors, however, all of the SortOrders are always zero so, as I'd expect, .OrderBy() and .OrderByDescending() don't affect the results.  I've sorted all of my content to make sure they have actual values.  So is this an Umbraco bug I should report?

            var rootNode = Model.AncestorContentOrSelf().Last();
    var L1Pages = rootNode.Children().AsEnumerable()
    .Where(x => x.ContentType.Alias == "navigationItem")
    .OrderByDescending(x => x.SortOrder);

     

Please Sign in or register to post replies

Write your reply to:

Draft