Copied to clipboard

Flag this post as spam?

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


  • Thomas 319 posts 606 karma points c-trib
    Sep 26, 2019 @ 13:26
    Thomas
    0

    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
    0

    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: https://www.codeproject.com/Questions/685831/error-An-object-reference-is-required-for-the-non

    ~ Jonathan

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

    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.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies