Copied to clipboard

Flag this post as spam?

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


  • Richard Terris 273 posts 714 karma points
    Mar 17, 2014 @ 18:35
    Richard Terris
    0

    uQuery Vs UmbracoHelper

    Hi guys,

    According to the documentation here (http://our.umbraco.org/documentation/Reference/Querying/uQuery/), I should now be using UmbracoHelper instead of uQuery, but I can't seem to find equivalent methods for things like GetNodesByType()

    Does anyone have a deeper understanding of this? The UmbracoHelper documentation doesn't seem fully fledged as yet.

    Thanks in advance,

    Richard

  • Dan Lister 415 posts 1970 karma points c-trib
    Mar 17, 2014 @ 18:59
    Dan Lister
    0

    I think you have to roll your own. Given a published content instance, you could run the following LINQ query:

    var children = node.Children.Where(n => n.Type.Equals("ChildDocTypeAlias"))
  • Andrew 3 posts 43 karma points
    Mar 17, 2014 @ 19:00
    Andrew
    100

    I tend to use the typed methods, like so:

    IPublishedContent home = Umbraco.TypedContentAtRoot().FirstOrDefault();
    IEnumerable<IPublishedContent> myDocumentTypes = home.Descendants("MyDocumentType");
    

    Note, .Descendants is an extension of IPublishedContent in Umbraco.Web.

  • Richard Terris 273 posts 714 karma points
    Mar 17, 2014 @ 22:02
    Richard Terris
    0

    These are both fine answers, though to be honest not something I couldn't do already.

    However, I was rather hoping there would be some equivalent methods to the uQuery methods. If you take a look at uQuery, it's now in Umbraco.Core namespace, you'll see a whole load of really useful methods such as GetNodeIdByType and others.

    The trouble with uQuery now, as far as I can tell, is that all returned objects are are of Umbraco.NodeFactory.Node type, which is now obsolete

    I have written a method which converts Node to IPublishedContent and vice versa, but this only serves to allow me to use uQuery, which I'm trying to move away from.

  • Richard Terris 273 posts 714 karma points
    Mar 17, 2014 @ 22:18
    Richard Terris
    0

    Marking yours as the answer Andrew as it does work, but I guess the real answer to my question is that equivalent methods don't exist

Please Sign in or register to post replies

Write your reply to:

Draft