假设我有帖子和评论集,
public class Post {
String title;
List<Comment> comments;
}
public class Comment {
Date date;
String author;
String comment;
}
我希望能够知道某个帖子标题在特定日期范围内的最新评论是什么。结果显示为具有以下结构的投影:
public class Result {
String postTitle;
Date commentDate
String commentAuthor;
String comment;
}
我正在努力让它发挥作用,我尝试了几种方法,但无法做到正确。我对此有一个索引,但我不太确定如何仅获取子元素的最后一个条目。我正在获取日期范围内的所有记录,而不仅仅是最后一条记录。
这是我的索引:
public Posts_LastCommentDateRange() {
map = "docs.Posts.SelectMany(post => post.comments, (post, comment) => new {" +
" post.title," +
" commentDate = comment.date," +
" commentAuthor = comment.author," +
" comment.comment" +
"})";
}
这是我的查询:
List<Result> res = session.query( Result.class, Posts_LastCommentDateRange.class )
.whereEquals( "title", "RavenDB Date Range" )
.whereBetween( "commentDate", "2019-01-02T10:27:18.7970000Z", "2019-01-25T15:01:23.8750000Z" )
.selectFields( Result.class )
.toList();
任何帮助或方向将不胜感激。
谢谢