Copied to clipboard

Flag this post as spam?

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


  • Dmitriy 168 posts 588 karma points
    Oct 18, 2017 @ 09:20
    Dmitriy
    0

    Optimal way to check page for children

    Hello. I need to know, has a page children or not? I don't need to get any children, I just want to know has it or not.

     // BAD WAY
        page.Children().Count() > 0 
    

    There is a EXISTS operator in SQL-syntax, but how to implement it with LINQ fluent syntax?

    Or another way to do what I want?

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 18, 2017 @ 09:25
    Alex Skrypnyk
    103

    Hi Dmitriy

    Any() method is a way how to do it:

    if (page.Children().Any())
    {
    
    }
    

    Thanks,

    Alex

  • Dmitriy 168 posts 588 karma points
    Oct 18, 2017 @ 12:13
    Dmitriy
    0

    Thanks, Alex. But it is not I want.

    When page.Children() is done, we have got a full set of children first, I guess it is not good for performance. But may be Umbraco-developers solved that problem somehow. Do you know anything about that?

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Oct 18, 2017 @ 13:25
    Alex Skrypnyk
    1

    It's not a performance problem when you are working with IPublishedContent entities, they are not touching database so it's not a problem.

    Be aware - do not use IContent entities, they are working with the database.

    Read more about common pitfalls: https://our.umbraco.org/documentation/reference/Common-Pitfalls/

    Thanks,

    Alex

  • Dmitriy 168 posts 588 karma points
    Oct 19, 2017 @ 09:09
    Dmitriy
    0

    Thanks again, Alex, I'll check it.

Please Sign in or register to post replies

Write your reply to:

Draft