Guest User

Untitled

a guest
Jul 15th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // Get comments
  2. var q = (
  3. from C in db.tblComments
  4. where
  5. C.CategoryID == Category &&
  6. C.IdentifierID == Identifier
  7. join A in db.tblForumAuthors on C.UserID equals A.Author_ID
  8. orderby C.PostDate descending
  9. select new
  10. {
  11. C,
  12. A.Username,
  13. UpVotes = (from V in db.tblCommentVotes where V.CommentID == C.ID && V.UpVote == true select new { V.ID }).Count(),
  14. DownVotes = (from V in db.tblCommentVotes where V.CommentID == C.ID && V.UpVote == false select new { V.ID }).Count()
  15. }
  16. )
  17. .Skip(ToSkip > 0 ? ToSkip : 0)
  18. .Take(ToTake > 0 ? ToTake : int.MaxValue);
  19.  
  20. var q = (
  21. from C in db.tblComments
  22. where
  23. C.CategoryID == Category &&
  24. C.IdentifierID == Identifier
  25. join A in db.tblForumAuthors on C.UserID equals A.Author_ID
  26. // the following two lines are the left outer join thing.
  27. join voteTemp in db.tblCommentVotes on voteTemp.CommentID equals C.ID into voteJoin
  28. from vote in voteJoin.DefaultIfEmpty()
  29. orderby C.PostDate descending
  30. group C by new { Comment = C, Username = A.Username } into g
  31. select new
  32. {
  33. g.Key.Comment,
  34. g.Key.Username,
  35. UpVotes = g.Count(x => x.UpVote),
  36. DownVotes = g.Count(x => !x.UpVote)
  37. }
  38. )
  39. .Skip(ToSkip > 0 ? ToSkip : 0)
  40. .Take(ToTake > 0 ? ToTake : int.MaxValue);
  41.  
  42. db.tblComments.Where(c => c.CategoryID == Category && c.IdentifierID == Identifier)
  43. .Join(db.tblForumAuthors, c => c.UserID, a => a.Author_ID,
  44. (c, a) =>
  45. new
  46. {
  47. CommentID = c,
  48. AuthorName = a.UserName,
  49. UpVotes = c.Join(db.tblCommentVotes, c => c.CommentID
  50. v => v.CommentID,
  51. (c, v) => v).Count(v => v.UpVote)
  52. DownVotes = c.Join(db.tblCommentVotes, c => c.CommentID
  53. v => v.CommentID,
  54. (c, v) => v).Count(v => v.DownVote)
  55. });
Add Comment
Please, Sign In to add comment