Copied to clipboard

Flag this post as spam?

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

  • Thomas 310 posts 597 karma points c-trib
    Sep 26, 2019 @ 13:26

    Umbraco 8 - GetPagedDescendants filter

    I'm having some trouble with the filter again..

    var filter =  SqlContext.Query<IContent>().Where(x => x.IsCulturePublished(culture))
    IEnumerable<IContent> items = contentService.GetPagedDescendants(pageId, page, pageSize, out long TotalChildren, filter, Ordering.By("date", Direction.Descending, null, true));

    I'm getting this... "An object reference is required for the non-static field, method or property SqlContext.Query

    And if i add

    new SqlContext.Query<IContent>().Where(x => x.IsCulturePublished(culture))

    Then I get "The type name Query<> does not exits in the type SqlContext

    Am I using it wrong?

  • Jonathan Distenfeld 105 posts 618 karma points
    Sep 27, 2019 @ 10:37
    Jonathan Distenfeld

    Hi Thomas,

    I assume that you are trying to achieve this in a static method?

    Please consider to make this method non-static and the error should disapear. Otherwise you would have to create a new Instance of "SqlContext" and Call .Query<>() on the new instance.

    For more information:

    ~ Jonathan

  • Francis Benyah 35 posts 111 karma points
    Nov 19, 2020 @ 11:14
    Francis Benyah

    You could just inject it if using V8 and a static method and/class

    ISqlContext _sqlContext = Current.Factory.GetInstance<ISqlContext>();
    IQuery<IContent> filter = _sqlContext.Query<IContent>().Where(x => x.ContentTypeId.Equals(descendantType.Id));

    That works well.

    A bit late but hopefully it helps someone. Not sure if there is a better way of doing it though.

Please Sign in or register to post replies

Write your reply to: