2016-07-04 75 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(); 
相關問題