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 164 posts 277 karma points
    6 days ago
    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 5178 posts 18868 karma points MVP 2x admin c-trib
    6 days ago
    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 164 posts 277 karma points
    6 days ago
    Doogie Talons
    0

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

    Rob

  • Alex Skrypnyk 5178 posts 18868 karma points MVP 2x admin c-trib
    6 days ago
    Alex Skrypnyk
    0

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

  • Doogie Talons 164 posts 277 karma points
    6 days ago
    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 5178 posts 18868 karma points MVP 2x admin c-trib
    6 days ago
  • Doogie Talons 164 posts 277 karma points
    6 days ago
    Doogie Talons
    1

    Cheers, looking at the wrong one :) Thanks.

    Rob

Please Sign in or register to post replies

Write your reply to:

Draft