In my application there are multiple areas which require a list of query results sorted by the same field.
So I have defined a static index like this:
public sealed class BlogPosts_OrderedByPublishDateDesc : AbstractIndexCreationTask<BlogPost>
{
public BlogPosts_OrderedByPublishDateDesc()
{
Map = blogPosts => from blogPost in blogPosts
orderby blogPost.PublishedOn descending
select new
{
blogPost.PublishedOn
};
}
}
This works, but sorting within an Map definition somehow sounds like a bad idea.
So, far I haven’t found any evidence for or against.
What’s the recommended approach?
Sorting on the map is a noop, it has no affect on the actual order of returned items.
You need to order during the query to make this happen