dimanche 15 octobre 2017

How to get and select real correct Data Asynchronously up to date

In a website, there are an article page and when i go to the article page, it displays the article and the first 10 comments belong to this article.

And there are some button when click it, it asynchronously display the rest of all comments by AJAX.

The question is that suppose after the article page is loaded with first 10 comments, User that own comment or Admin delete it, how to select the rest of comments? if i skip fisrt 10 comemnts from select statement, there are some comments not selected.

As Example:

suppose the comments IDs are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20

First 10 comments IDs i select are: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

IEnumerable<Comment> comments = (from a in context.Comments
                                         where a.ArticleID == ArticleID
                                         orderby a.CommentDate descending
                                         select new Comment
                                         {
                                             CommentID = a.CommentID,
                                             CommentContent = a.CommentContent,
                                             CommentDate = a.CommentDate,


                                         }).ToList().Take(10);

suppose User that own comment or Admin delete 2 comments whose IDs: 9, 10

then the first ten comments in databse will become: 1, 2, 3, 4, 5, 6, 7, 8, 11, 12

when i try to get the rest of comments and skip first 10 comments, then the result is: 13, 14, 15, 16, 17, 18, 19, 20

IEnumerable<Comment> comments = (from a in context.Comments
                                         where a.ArticleID == ArticleID
                                         orderby a.CommentDate descending
                                         select new Comment
                                         {
                                             CommentID = a.CommentID,
                                             CommentContent = a.CommentContent,
                                             CommentDate = a.CommentDate,


                                         }).ToList().Skip(10);

so there are two comments 11 & 12 i cannot see them, because comments with IDs: 11, 12 will be consider with the first 10 comments.

Aucun commentaire:

Enregistrer un commentaire