The query results cannot be enumerated more than once

前端 未结 2 560
夕颜
夕颜 2020-12-21 13:29

Consider the following methods. I am getting exception as asked , while repeater binding.

Bindrepeater:

private void BindRepeater()
{
    var idx =          


        
相关标签:
2条回答
  • 2020-12-21 14:01

    You may want to persist your results as a collection, not an IQueryable.

    var list = result.ToArray();
    
    itemcount = list.Length;
    return list.Skip(skip).Take(10);
    

    The above code may not be correct for paging. You likely will have to run the query twice.

    0 讨论(0)
  • 2020-12-21 14:09

    When you assign itemcount you are executing the query the first time. Why do you need this? My suggestion would be not to retrieve the item count there and just

    return result.Skip(skip).Take(10).ToList();
    

    Basically you can't have both, fetch only the results you need and retrieve the total count in one query. You could use two seperate querys though.

    0 讨论(0)
提交回复
热议问题