分类目录

链接

2017 年 12 月
 123
45678910
11121314151617
18192021222324
25262728293031

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > Others > 正文
嵌套评论列表设计及查询
Others 暂无评论 阅读(593)

表设计

  1. create table comments(
  2.  
  3.     id int pk,//主键
  4.  
  5.      content varchar(200),//内容
  6.  
  7.      time datetime,//时间
  8.  
  9.      user_id int,//评论者ID
  10.  
  11.      parent_id int,//父级评论ID
  12.  
  13.      article_id int,//对像ID,比如文章ID
  14.  
  15. );

//以下仅手打示例代码

 

  1. //先取出要展示的10条评论
  2. var commentList = db.comments.where(f=>f.article_id==Id).Take(10).ToList();
  3. //取出父级ID
  4. var parentIdList = commentList .select(f=>f.parent_id).ToList();
  5. //取出父级评论列表
  6. var parentCommentList = db.comments.where(f=> parentIdList .contains(f.id) ).ToLsit();
  7.  
  8. //最后添加到主评论
  9.  
  10. commentList .addRange(parentCommentList );

 

客户端使用

 

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:嵌套评论列表设计及查询 | Bruce's Blog

发表评论

留言无头像?