2015-03-08 45 views
0

我有以下Post类:查找出来,如果用户喜欢具体的意见

public class Post 
{ 
    public string Id {get;set;} 
    public string Content {get;set;} 
    public IList<Comment> Comments {get;set;} 
} 

public class Comment 
{ 
    public int OrderNumber {get;set;} //kind of CommentId 
    public string AuthorId {get;set;} 
    public string Text {get;set;} 
    public IList<string> Voters {get;set;} //Ids of users who liked the post 
} 

可能有成千上万的喜好为每个评论的,但我需要在客户机上只显示他们的数量,所以我创建以下索引:

Map = posts => from post in posts 
       select new { 
          Id = post.Id, 
          Content = post.Content, 
          Comments = post.Comments.Select(x => 
           new CommentProjection { 
           AuthorId = x.AuthorId, 
           Text = x.Text, 
           VotersCount = x.VotersCount 
                }), 
          }; 

问题是我需要突出显示那些用户已经喜欢的评论。有没有办法修改上述索引以将这些信息添加到查询结果中?

+0

好像它是很多网站的一个问题。有些人根本没有这个功能,有些人只是在放置它后立即想象你,但如果你刷新一个页面,没有具体的东西会显示出来。 – SiberianGuy 2015-03-10 10:23:50

回答

3

你可以用另一种方式来做,跟踪用户的评论,这样你就可以显示他们喜欢的评论。

+0

我觉得这是一个正确的方式,但请您更具体地了解这个想法? – SiberianGuy 2015-03-10 10:21:35

+2

保留用户在用户文档中喜欢的评论。 – 2015-03-11 11:37:35

0

为什么不有一个单独的实体叫做Votes?它可以有3个简单的字段,一个用户表的外键和一个用于注释表的外键。第三个(比特)表示这是一个downvote还是upvote(like)。

然后,您可以直接和方便地查询该表(通过用户ID和那些有“给予好评”过滤)