List query object support in the repository

We have seen the GetAllPosts method, which includes related data for all implementations. Since we are creating a common query, which could be consumed in multiple places, we need to include this as a filter in the GetAllPostsQuery object:

    public class GetAllPostsQuery    {      public GetAllPostsQuery(bool includeData)      {        this.IncludeData = includeData;      }      public bool IncludeData { get; set; }    }

The GetAllPostsQuery consumes only the IncludeData filter in the type, which doesn't filter any data from the result set, but only excludes/includes related data. The following code would create a contract to enforce consumers to implement handle methods:

    public interface IPostQueryHandler<T> where T : class { ...

Get Mastering Entity Framework Core 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.