Single query object support in the repository

We have seen how a list of objects was returned from the repository in a generic fashion. Let's have a provision to return a single object from the repository:

    public interface IPostRepositoryWithQueries    {      // Code removed for brevity      Post GetSingle<T>(T query) where T : class;      Task<Post> GetSingleAsync<T>(T query) where T : class;    }

The preceding code adds synchronous and asynchronous methods to return a single Post object from the repository, still retaining the generic implementation since it could be used by multiple query objects that might return individual Post objects:

    public class GetPostByIdQuery    {      public GetPostByIdQuery(int? id, bool includeData)      {        this.Id = id; this.IncludeData = ...

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.