Search In
Hi
I can't get the .OrderBy to work in umbraco v 4.7.0What 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>
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.
did you reference the @inherits umbraco.MacroEngine ???
and ensure that your razorcode is embed into @{}
Example
@{
@foreach() {}
}
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:
10551056
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.
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 :-)
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.
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.
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.
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...