public async Task <Post> FindBySlugAsync(string slug, PostIncludeOptions includeOptions = null, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(slug)) { throw new ArgumentNullException(nameof(slug)); } // BUG 20191013 // https://github.com/aspnet/EntityFrameworkCore/issues/18020 // https://github.com/aspnet/EntityFrameworkCore/issues/1222 // https://github.com/aspnet/EntityFrameworkCore/issues/18234 // String equals with StringComparison.InvariantCultureIgnoreCase can't work ! var query = Repository.GetQueryable(); if (includeOptions?.IncludeCategory == true) { query = query.Include(t => t.Categories).ThenInclude(c => c.Category); } if (includeOptions?.IncludeTags == true) { query = query.Include(t => t.Tags).ThenInclude(t => t.Tags); } if (includeOptions?.IncludeUser == true) { query = query.Include(t => t.User); } return(await query.FirstOrDefaultAsync(t => t.Slug.ToLower() == slug.ToLower())); }
public async Task <Post> GetByIdAsync(int id, PostIncludeOptions includeOptions = null, CancellationToken cancellationToken = default) { var query = Repository.GetQueryable(); if (includeOptions?.IncludeCategory == true) { query = query.Include(t => t.Categories).ThenInclude(c => c.Category); } if (includeOptions?.IncludeTags == true) { query = query.Include(t => t.Tags).ThenInclude(t => t.Tags); } if (includeOptions?.IncludeUser == true) { query = query.Include(t => t.User); } return(await query.FirstOrDefaultAsync(t => t.Id == id)); }