【发布时间】:2016-11-20 23:57:35
【问题描述】:
假设我们有以下地图索引:
public class CommentsIndex : AbstractIndexCreationTask<Post>
{
public class IndexResult
{
public string PostId {get;set;}
public DateTime CommentDateTime {get;set;}
}
public CommentsIndex()
{
Map = posts => from post in posts
from comment in post.Comment
select new { PostId = post.Id, CommentDateTime = comment.DateTime };
}
}
此索引查询的结果将是 Post 文档的集合。但是如何通过CommentDateTime查询呢?以下查询肯定不起作用,因为CommentDateTime 不是Post 文档的一部分:
_documentSession.Query<Post, CommentsIndex>().Where(x => x.CommentDateTime < DateTime.UtcNow).ToList();
P。 S. 我知道我可以使用实时投影或调用AsProjection 来塑造索引查询结果,但我想对于这种简单的情况应该有更自然的解决方案。
【问题讨论】: