Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 14:25
    Doogie Talons
    0

    Umbraco 8 Query builder returning all nodes regardless of type selected

    Hi just using umbraco 8 and the query builder.

    When I select the content type, it just returns all nodes regardless.

    For example

    Umbraco.ContentAtRoot().FirstOrDefault() .Children("socialLink") .Where(x => x.IsVisible())

    Just returns all the prime nodes. and not the ones I actually want.

    Have I missed something ?

    Rob

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Apr 16, 2019 @ 14:38
    Alex Skrypnyk
    100

    Hi

    Try this code:

    var socialLinks = Umbraco.ContentAtRoot().FirstOrDefault().Children().Where(x => x.IsVisible()).OfType<SocialLink>();
    

    .Children("socialLink") doesn't work in v8, you can't get all nodes of specified document type. Try to use ModelsBuilder and OfType

    Thanks,

    Alex

  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 14:44
    Doogie Talons
    0

    So the query builder is now defunct ? What is modelsbuilder ?

    Rob

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Apr 16, 2019 @ 14:54
    Alex Skrypnyk
    0

    No, just Children by doctype as a string doesn't work.

  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 14:59
    Doogie Talons
    0

    Ok just ammended it to..

    var socialLinks = Model.Root().Descendants().Where(x => x.IsVisible()).OfType<SocialLink>();
    

    I take it this is the correct way to get all regardless of level.

    Now one last quesiton where would I research your solution ie' how would I know to have used .OfType

    Thanks for your help Alex

    Rob

  • Alex Skrypnyk 6131 posts 23950 karma points MVP 7x admin c-trib
    Apr 16, 2019 @ 16:17
  • Doogie Talons 183 posts 318 karma points
    Apr 16, 2019 @ 16:18
    Doogie Talons
    1

    Cheers, looking at the wrong one :) Thanks.

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft