CmsKit - Fix MongoDb Query for Comment details

pull/8588/head
enisn 5 years ago
parent 5a518b58ae
commit 078a4b540b

@ -23,23 +23,28 @@ namespace Volo.CmsKit.MongoDB.Comments
public async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default) public async Task<CommentWithAuthorQueryResultItem> GetWithAuthorAsync(Guid id, CancellationToken cancellationToken = default)
{ {
var query = from comment in (await GetMongoQueryableAsync(cancellationToken)) var dbContext = await GetDbContextAsync();
join user in (await GetDbContextAsync(cancellationToken)).CmsUsers on comment.CreatorId equals user.Id var commentQueryable = await GetMongoQueryableAsync(cancellationToken);
where id == comment.Id var userQueryable = dbContext.Collection<CmsUser>();
select new CommentWithAuthorQueryResultItem
{ var joined = commentQueryable.Join(userQueryable, x => x.CreatorId, x => x.Id, (comment, user) => new
Comment = comment, {
Author = user Comment = comment,
}; User = user
});
var commentWithAuthor = await query.FirstOrDefaultAsync(GetCancellationToken(cancellationToken)); var commentWithAuthor = await joined.FirstOrDefaultAsync(GetCancellationToken(cancellationToken));
if (commentWithAuthor == null) if (commentWithAuthor == null)
{ {
throw new EntityNotFoundException(typeof(Comment), id); throw new EntityNotFoundException(typeof(Comment), id);
} }
return commentWithAuthor; return new CommentWithAuthorQueryResultItem()
{
Comment = commentWithAuthor.Comment,
Author = commentWithAuthor.User
};
} }
public async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync( public async Task<List<CommentWithAuthorQueryResultItem>> GetListAsync(

Loading…
Cancel
Save