Copied to clipboard

Flag this post as spam?

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


  • Thomas 195 posts 422 karma points
    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 23 posts 94 karma points
    4 days ago
    Francis Benyah
    0

    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:

Draft