Copied to clipboard

Flag this post as spam?

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


  • Christian Palm 278 posts 273 karma points
    Apr 12, 2011 @ 22:44
    Christian Palm
    0

    OrderBy not working?

    Hi

    I can't get the .OrderBy to work in umbraco v 4.7.0
    What is wrong?

    @{
    var blogposts = Model.Descendants("BlogPost");
    var children = Model.Children;
    }
    <ul>
    @foreach (var item in blogposts.OrderBy("Id desc"))
    {
    <li><a href="@item.Url">@item.Name - @item.Id</a></li>
    }
    </ul>
    <ul>
    @foreach (var item in blogposts.OrderBy("Id"))
    {
    <li><a href="@item.Url">@item.Name - @item.Id</a></li>
    }
    </ul>
    <ul>
    @foreach (var item in children.OrderBy("Id desc"))
    {
    <li><a href="@item.Url">@item.Name - @item.Id</a></li>
    }
    </ul>
    <ul>
    @foreach (var item in children.OrderBy("Id"))
    {
    <li><a href="@item.Url">@item.Name - @item.Id</a></li>
    }
    </ul>
  • Eran Meir 401 posts 543 karma points
    Apr 12, 2011 @ 22:59
    Eran Meir
    0

    is it working and you're getting a wrong output or it's not working because an error?
    i can't see something wrong with the code.

  • Toni Becker 146 posts 425 karma points
    Apr 12, 2011 @ 23:10
    Toni Becker
    0

    did you reference the @inherits umbraco.MacroEngine ???

     

  • Toni Becker 146 posts 425 karma points
    Apr 12, 2011 @ 23:12
    Toni Becker
    0

    and ensure that your razorcode is embed into @{}

    Example

    @{

    @foreach() {}

    }

  • Christian Palm 278 posts 273 karma points
    Apr 12, 2011 @ 23:24
    Christian Palm
    0

    I do not get any error, just wrong output. Adding desc does not change the order. The order in the output is taken from the sort order in Umbraco.

    This is my full test scripts:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @foreach (var item in @Model.Children.OrderBy("Id")) {
    @item.Id <br />
    }
    @foreach (var item in @Model.Children.OrderBy("Id desc")) {
    @item.Id <br />
    }

    With my sample data I always get:

    1055
    1056
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 13, 2011 @ 09:52
    Sebastiaan Janssen
    3

    Hey Christian, the problem is that native properties (Id, Level, CreateDate, etc) do not sort at the moment because of a bug, this has been solved in recent commits to the 4.7.1 branche. You can download and build it yourself, it's very stable and I am going live with that code tomorrow. 

    I still have a build up over here if you don't want to build it yourself.

  • Alexander Bryukhov 19 posts 68 karma points c-trib
    Apr 16, 2011 @ 11:07
    Alexander Bryukhov
    0

    Hi Sebasiaan,

    I've tried to download your build (set 2069) and the latest nightly (4.7.0.381).

    The OrderBy sorting bug disappeared, but there are other issue in these both new builds - the doctype and mediatype property pages in the admin console are show nothing at all except tab headers :-(

    Do you meet this issue in the latest builds? I should say here, that my current installation is not clear 4.7 but upgraded 4.6.1. Maybe my problem reasons are here...

    Maybe there is an short guide to rebuild only one library (i think MacroEngine or...?) with this sort fix only? The current project is very close to production stage and native properties sotring feature is very important.

    Thanks in advance :-)

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 16, 2011 @ 13:34
    Sebastiaan Janssen
    0

    If you can revert to your previous version and the property pages work again, then do that. All you really need is in deed the MacroEngines dll. But this problem really can't be because of the upgrade to the nightly build because I think nothing except for the MacroEngines dll was changed. I don't know what the problem in your case is though. 

    The PDB files are there, why not hit CTRL+ALT+P in Visual Studio and attaching to the worker process for your site and see what exceptions are being thrown, you might find the problem soon enough.

    My guess is that it's an incompatible datatype that's causing problems.

  • Alexander Bryukhov 19 posts 68 karma points c-trib
    Apr 16, 2011 @ 14:49
    Alexander Bryukhov
    0

    Sebastiaan,

    thank you for the explicitly pointed dll.

    After I reverted the bin folder content to its original 4.7.0 state and replaced the MacroEngines.dll with the one from your build (earliaer in this thread), the both problems are gone. Now the normal work with the doctypes is possible and the items are sorted properly (I've used "sortOrder desc" by the way).

    Thanks again.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 16, 2011 @ 14:57
    Sebastiaan Janssen
    0

    Very strange! What did you do to upgrade? Just overwriting the /bin folder should've been enough.

    That said, this is a nightly and there might be work in progress that I'm not aware of, but I didn't have this issue with my sites (2 of which upgraded from 4.6) at all.

  • Alexander Bryukhov 19 posts 68 karma points c-trib
    Apr 16, 2011 @ 17:15
    Alexander Bryukhov
    1

    Sebastiaan,

    when I did my upgrade to 4.7 - it was a typical set of steps - /bin, /umbraco and /umbraco_client folders. Moreover, I've removed the version parameter value from the web.config to enforce the install/upgrade procedure, which was ended up with nothing special as far as I can see.

    What about doctype editor problem - this strange behavior I can see with both your and 381 nightly build /bin folders. The normal behavior - with 4.7.0 original /bin only. Maybe the content of the /umbraco folder from your package should do the trick? (some aspx|ascx files are newer?)...

    Anyway, the fully original /bin from 4.7.0 with only  one updated MacroEngines.dll from your package solves my problems at the moment :-)

    BTW, the full /bin folder from your package with PDB files and Visual Studio and working process attachment was showing absolutly nothing for me. I use in my dev process the manually started file-mode IIS Express at the moment - maybe this is the reason...

  • Eran Meir 401 posts 543 karma points
    Apr 22, 2011 @ 13:41
    Eran Meir
    0

    Alexander, i've tried the solution of replacing the MacroEngines.dll but it won't work, did you do something else to make it work?

    i'm trying to do

    foreach (var dateFolder in Model.AncestorOrSelf("Blog").Children.OrderBy("Name desc")) { }
  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 22, 2011 @ 14:06
    Sebastiaan Janssen
    0

    What is not working about this?

    Is the nodetypeALIAS of the blog called "Blog" with a capital B? Did you replace the MacroEngines.dll with the one in the zip file I posted?

    Just checking: You're probably trying to get the folders by year right?

  • Eran Meir 401 posts 543 karma points
    Apr 22, 2011 @ 14:47
    Eran Meir
    0

    the nodetypealias of the blog called "Blog" with a capital B. i did replace the dll with the one in the zip.
    and you're right about the year, i'm trying to get an Archive blog by the years
    i'm getting 2010, 2011 and not 2011, 2010 

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 22, 2011 @ 14:54
    Sebastiaan Janssen
    0

    So what's not working?

  • Eran Meir 401 posts 543 karma points
    Apr 22, 2011 @ 15:12
    Eran Meir
    0

    i'm not getting the order i want
    i want to get
    2011
    2010

    instead i get 
    2010
    2011

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Apr 22, 2011 @ 15:27
    Sebastiaan Janssen
    0

    Alright, I've just tried your code and it works just fine for me (with the same updated build that your using). So I think the MacroEngines.dll was not updated correctly for you.

    For now the only solution I have would be the code below. Please report this on CodePlex, seems like a bug to me!

      @using umbraco.MacroEngines
      @{ 
        var nodes = new List<DynamicNode>(); 
        foreach (dynamic dateFolder in Model.AncestorOrSelf("BlogOverview").Children)
        { nodes.Add(dateFolder); }
        foreach(var node in nodes.OrderBy(x => x.Name))
        <span>@node.Name</span}
      }
  • Eran Meir 401 posts 543 karma points
    Apr 22, 2011 @ 15:37
    Eran Meir
    0

    now i see there's already a report about it http://umbraco.codeplex.com/workitem/30198
    I hope it will be fixed in 4.7.1

    I will try your solution, thank you for you help :)

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jun 19, 2011 @ 20:21
    Dan Diplo
    0

    Just found this thread as I was having the same problem. There is a way around getting sorting to work on native properties in 4.7 by using the @CurrentModel object instead of @Model. That way you can do this:

    foreach (var dateFolder in @CurrentModel.AncestorOrSelf("Blog").Descendants().Items.OrderByDescending(i => i.Name)) { }

    Just remember to add

    @inherits umbraco.MacroEngines.DynamicNodeContext

    .

  • Eran Meir 401 posts 543 karma points
    Jun 19, 2011 @ 21:28
    Eran Meir
    0

    thanks dan, i will try it.

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jun 20, 2011 @ 14:20
    Sebastiaan Janssen
    1

    Just a heads up, 4.7.1 will be out soon (possibly early July) and this should not be a problem any more.

Please Sign in or register to post replies

Write your reply to:

Draft