2016-07-04 38 views
2

使用MVC实体框架我使用AJAX调用带有跳过和取参数的函数。LINQ IQueryable使用跳过返回相同的行并采取

[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) 

} 

我的问题是,每次我打电话即使我调试相同的行返回的功能和跳跃价值增量,而我行100S要从中提取。

+0

是的,即使我通过增加每次12跳过相同的顺序相同的行。 – Jackmagic1

+0

您是否[跟踪](https://msdn.microsoft.com/en-us/data/dn469464.aspx)EF调用? –

+0

我认为你有多个SearchContent()方法。只有take和skip的那个有两个参数,而发布的有8个参数。 – jdweng

回答

1

的解决方案是由子句添加另一个ORDER BY Damien_The_Unbeliever的建议

-1
//pageSize is how many rows you want to skip every time and 
    //index is like page number first time index should be 0 then 1 every time index will be increased by one 
    var c = await context.ContentEntities.Skip(pageSize * index).Take(pageSize).ToListAsync(); 
相关问题