Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Get comments
- var q = (
- from C in db.tblComments
- where
- C.CategoryID == Category &&
- C.IdentifierID == Identifier
- join A in db.tblForumAuthors on C.UserID equals A.Author_ID
- orderby C.PostDate descending
- select new
- {
- C,
- A.Username,
- UpVotes = (from V in db.tblCommentVotes where V.CommentID == C.ID && V.UpVote == true select new { V.ID }).Count(),
- DownVotes = (from V in db.tblCommentVotes where V.CommentID == C.ID && V.UpVote == false select new { V.ID }).Count()
- }
- )
- .Skip(ToSkip > 0 ? ToSkip : 0)
- .Take(ToTake > 0 ? ToTake : int.MaxValue);
- var q = (
- from C in db.tblComments
- where
- C.CategoryID == Category &&
- C.IdentifierID == Identifier
- join A in db.tblForumAuthors on C.UserID equals A.Author_ID
- // the following two lines are the left outer join thing.
- join voteTemp in db.tblCommentVotes on voteTemp.CommentID equals C.ID into voteJoin
- from vote in voteJoin.DefaultIfEmpty()
- orderby C.PostDate descending
- group C by new { Comment = C, Username = A.Username } into g
- select new
- {
- g.Key.Comment,
- g.Key.Username,
- UpVotes = g.Count(x => x.UpVote),
- DownVotes = g.Count(x => !x.UpVote)
- }
- )
- .Skip(ToSkip > 0 ? ToSkip : 0)
- .Take(ToTake > 0 ? ToTake : int.MaxValue);
- db.tblComments.Where(c => c.CategoryID == Category && c.IdentifierID == Identifier)
- .Join(db.tblForumAuthors, c => c.UserID, a => a.Author_ID,
- (c, a) =>
- new
- {
- CommentID = c,
- AuthorName = a.UserName,
- UpVotes = c.Join(db.tblCommentVotes, c => c.CommentID
- v => v.CommentID,
- (c, v) => v).Count(v => v.UpVote)
- DownVotes = c.Join(db.tblCommentVotes, c => c.CommentID
- v => v.CommentID,
- (c, v) => v).Count(v => v.DownVote)
- });
Add Comment
Please, Sign In to add comment