Skip to content

Instantly share code, notes, and snippets.

@vaygeth89
Created July 26, 2023 12:42
Show Gist options
  • Save vaygeth89/11f563143d6ceeaedb181be1d4c05c49 to your computer and use it in GitHub Desktop.
Save vaygeth89/11f563143d6ceeaedb181be1d4c05c49 to your computer and use it in GitHub Desktop.
public class ArticleReadingQuryables
{
private readonly AppDbContext _context;
public ArticleReadingQuryables(AppDbContext dBContext)
{
_context = dBContext;
}
public IQueryable<Article> Published()
{
return _context.Article.Where(e => e.IsPublished)
.Include(e => e.Publisher)
.OrderByDescending(e => e.PublishedOn);
}
public IQueryable<Article> WithReactionsAndComments()
{
return _context.Article.Include(e => e.Comments).ThenInclude(e => e.Replies);
}
public IQueryable<Article> WithReactions()
{
return _context.Article.Include(e => e.Reactions.Where(r => r.IsLiked || r.IsRead));
}
public IQueryable<Article> Latest()
{
return Published()
.OrderByDescending(e => e.PublishedOn);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment