public IList <Post> Posts(int pageNo, int pageSize) { var posts = _dbContext.Set <Post>() .Where(p => p.Published) .OrderByDescending(p => p.PostedOn) .Skip(pageNo * pageSize) .Take(pageSize) .Include(p => p.Category) .ToList(); var postIds = posts.Select(p => p.Id).ToList(); return(_dbContext.Set <Post>() .Where(p => postIds.Contains(p.Id)) .OrderByDescending(p => p.PostedOn) .Include(p => p.Tags) .ToList()); }
public BlogService(IBlogContext context, IMapper mapper) { _context = context; _repository = _context.Set <Blog>(); _mapper = mapper; }
public void Create(T item) { _database.Set <T>().Add(item); _database.SaveChanges(); }