Duplicate strings when using orderby, Skip () and Take () using LINQ

I use the following code to query my database:

private const int PAGE_SIZE = 10;

public static IList<Image> GetTopImagesForUser(String connectionString, int userID, int page)
{
    dbDataContext db = new dbDataContext(connectionString);
    var images = (from p in db.Images
                  where (p.SubmitterUserIndex == userID &&
                         p.URL != "none" &&
                         p.ThumbURL != "none")
                  orderby p.Rep descending
                  select p).Skip(page * PAGE_SIZE).Take(PAGE_SIZE);
    /* snip */
    return topImages;
}

If I call this code with page 0, everything will work the way I want it - I get a beautifully ordered list, 10 results, everything is correct.

1, , 0, 1. , . , . , URL ThumbURL "none". . , , - , , , , .

, , , orderby, , .

public static IList<Image> GetAllImagesForUser(String connectionString, int userID, int page)
{
    dbDataContext db = new dbDataContext(connectionString);
    var images = (from p in db.Images
                  where (p.SubmitterUserIndex == userID &&
                         p.URL != "none" &&
                         p.ThumbURL != "none")
                  orderby p.SubmitTime descending
                  select p).Skip(page * PAGE_SIZE).Take(PAGE_SIZE);
    /* snip */
    return allImages;
}

- - ? , , , ? , .

+3
3

, " " ​​- - Rep? , .

orderby p.Rep descending, p.SubmitTime

( - , ), .

, LINQ to SQL? , SQL, , .

+8

, LINQ, SELECT ( sproc). , , Rep , SubmitTime, , .

Rep, . . , ; .

+2

Rep, , , . 10 , 100 1, , . order by, .

+1

Source: https://habr.com/ru/post/1705937/


All Articles