Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Model
- public class Post
- {
- public string Id { get; set; }
- public string Title { get; set; }
- // .... other things
- public List<View> Views { get; set; }
- }
- public class View
- {
- public DateTime ViewDate { get; set; }
- public string UserId { get; set; }
- }
- public class PostPreview
- {
- public string Id { get; set; }
- public string Title { get; set; }
- // none of the other things
- public int TotalViews { get; set; }
- }
- // Service to get a preview
- private readonly IMongoCollection<Post> _posts;
- public async Task<IList<PostPreview>> GetFrontPage(int limit, int skip)
- {
- var result = await _posts.Find(_ => true)
- .Project(p => new PostPreview
- {
- Id = p.Id,
- Title = p.Title,
- TotalViews = p.Views.Count
- })
- .Skip(skip).Limit(limit).ToListAsync();
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement