Copied to clipboard

Flag this post as spam?

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


  • Harry Spyrou 212 posts 604 karma points
    Dec 20, 2017 @ 12:12
    Harry Spyrou
    0

    .OrderBy("SortOrder") obsolete Umbraco 7.7

    Hello once again,

    I'm not sure if this is a C# question or an Umbraco question but the image explains everything.

    .OrderBy("SortOrder") obsolete

    So, .OrderBy("SortOrder") is obsolete. I can't find the strongly typed version of it in the Umbraco documentation. will someone be able to point me to the correct direction on where can I find it?

    Or which one is the one that I should use?

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Dec 20, 2017 @ 12:17
    Alex Skrypnyk
    0

    Hi Harry

    Yes, use strongly typed models, please.

    Thanks,

    Alex

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Dec 20, 2017 @ 12:17
    Alex Skrypnyk
    0

    Show me all the code of view?

  • Harry Spyrou 212 posts 604 karma points
    Dec 20, 2017 @ 13:16
    Harry Spyrou
    0

    Hi Alex, this is what I have:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using System.Web;
    
      @foreach (var roomBlock in Model.Content.Children.Where(x => x.IsVisible()).Take(6))
          {
           //content
          }
    

    I can't send the whole code because it's a big view, but this is the gist of it. Is there within umbraco documentation a better way to do sort order than the one that is about to be obsolete?

    Thanks for the reply Alex.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Dec 20, 2017 @ 14:04
    Alex Skrypnyk
    100

    Hi Harry

    Try this code:

    @foreach (var roomBlock in Model.Content.Children.Where(x => x.IsVisible()).Take(6).OrderBy(x => x.SortOrder))
    
  • Harry Spyrou 212 posts 604 karma points
    Dec 20, 2017 @ 14:25
    Harry Spyrou
    0

    That's what I was looking for. It's just C# isn't it? It doesn't have to do with Umbraco. I appreciate it.

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Dec 20, 2017 @ 14:26
    Alex Skrypnyk
    0

    Yes, it's just c#, have a look at all properties and helpers here : https://our.umbraco.org/documentation/reference/querying/ipublishedcontent/

    THanks,

    Alex

  • Bjarne Fyrstenborg 1281 posts 3992 karma points MVP 8x c-trib
    Dec 20, 2017 @ 14:34
    Bjarne Fyrstenborg
    0

    @Alex @Harry

    I guess you would sort the collection before selecting 6 items, right?

    @foreach (var roomBlock in Model.Content.Children.Where(x => x.IsVisible()).OrderBy(x => x.SortOrder).Take(6))
    

    /Bjarne

  • Alex Skrypnyk 6148 posts 24097 karma points MVP 8x admin c-trib
    Dec 20, 2017 @ 14:36
    Alex Skrypnyk
    0

    Hi Bjarne

    It depends on business needs :) I'm not sure how it should be sorted.

    Sort only 6 items - faster, but it can return wrong results of course if you need top 6 items sorted before

  • Harry Spyrou 212 posts 604 karma points
    Dec 20, 2017 @ 15:03
    Harry Spyrou
    0

    Hi Bjarne,

    I think it's the same thing in my case. I'll test it when the client adds content on the staging server and I'll let you know, if you're interested.

  • Marcio Goularte 388 posts 1360 karma points
    Dec 20, 2017 @ 16:11
    Marcio Goularte
    0

    Hello, One of the reasons that is obsolete, is that this method uses Dynamic. which will be discontinued in v8.

    https://our.umbraco.org/documentation/reference/Common-Pitfalls/#dynamics

  • Bjarne Fyrstenborg 1281 posts 3992 karma points MVP 8x c-trib
    Dec 20, 2017 @ 16:16
    Bjarne Fyrstenborg
    0

    Actually I think the collection is returned in sort order, so I don't think it is necessary unless you want to sort in descending order or by another property.

    If not the collection is in right sort order, it need to be sorted first if you not just want the first 6 items no matter which default order the collection has.

    /Bjarne

  • Harry Spyrou 212 posts 604 karma points
    Dec 20, 2017 @ 17:02
    Harry Spyrou
    0

    Ah, I didn't think of that. I'll test it out and see

Please Sign in or register to post replies

Write your reply to:

Draft