Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ IQueryable returning same rows with skip and take

Using MVC Entity Framework I'm calling a function with AJAX that passes in skip and take parameters.

[HttpGet]
public async Task<ActionResult> _ViewMore( int take, int skip)
{
    var c = await GetContent( take, skip);
    return View(c)
}

public async Task<List<PartialContent>> GetContentForCulture(int take, int skip)
{           
    return await ContextHelper.SearchContent(take, skip);
}

public static async Task<List<PartialContent>> SearchContent( int take, int skip)
{
    try
    {
        using (var context = new Context())
        {
            var content = context.ContentEntities.SearchContent(take, skip);

            var f = await content.Select(s => new PartialContent
            {
                Subtype = s.Subtype,
                Id = s.Id,
                MainImage = s.MainImage,

            }).ToListAsync();

            return f;
        }
    }
    catch (Exception ex)
    {
        //      Log.Err(ex.Message, ex);
        return null;
    }
}

public static IQueryable<T> SearchContent<T>(this IQueryable<T> source,  int take, int skip)
    where T : ContentEntity
{
    source.Where(m => m.IsPublished ).OrderByDescending(m => m.DatePublished).Skip(skip).Take(take)

}

My issue is that every time I call the function the same rows are returned even though I debug and the skip value increments, and I have 100s of rows to fetch from.

like image 289
Jackmagic1 Avatar asked Dec 29 '25 17:12

Jackmagic1


1 Answers

The solution was to add another order by clause as suggested by Damien_The_Unbeliever

like image 119
Jackmagic1 Avatar answered Dec 31 '25 07:12

Jackmagic1