public class BlogPost
{
public string Id { get; set; }
public string Title { get; set; }
public string Content { get; set; }
public int ViewCount { get; set; }
public string BlogPostCommentCollectionId { get; set; }
}
public class IBlogPostWithRecentCommentsQueryResult
{
public BlogPost Post { get; set; }
public ICollection<Comment> RecentComments { get; set; }
}
public class Comment
{
public int Id { get; set; }
public string Content { get; set; }
public DateTime CreatedOn { get; set; }
}
public class IBlogPostQueryResult
{
public BlogPost Post { get; set; }
public ICollection<Comment> RecentComments { get; set; }
}
public class GetPostWithTopRelatedComments : AbstractIndexCreationTask<BlogPost>
{
public GetPostWithTopRelatedComments()
{
Map = posts => from post in posts
select new {post.Id, post.Title };
TransformResults = (database, posts) => from post in posts
let CommentCollection = database.Load<BlogPostCommentCollection>(post.BlogPostCommentCollectionId)
select new { post, RecentComments = CommentCollection.Comments.OrderBy(c => c.CreatedOn).Take(10) };
}
}
I tested this code and it worked. Is there a better solution?