How can I do my IEnumerable work with PagedList

I am using Troy Goode paged List in my project.
Usually you just load it with IEnumerable, startindex and the number of elements, and it all works.
Now, however, I'm trying to pass it an IEnumerable, which I generate as follows:

private static IEnumerable<Color> GetColors(Query query)
{
    IndexSearcher searcher = new IndexSearcher(luceneIndexpath);
    Hits hitColl = searcher.Search(query);
    //Get all the unique colorId's
    List<int> ids = new List<int>();            
    int id = 0;
    for (int i = 0; i < hitColl.Length(); i++)
    {
        if (Int32.TryParse(hitColl.Doc(i).GetField("id").StringValue(), out id))
            ids.Add(id);                
    }
    foreach (int uniqueId in ids.Distinct<int>())
    {
        yield return ColorService.GetColor(uniqueId);
    }
}

- EDIT - PagedList works, but asks for revenue for ALL of my Color objects, and not just for paged pages. This course disables all use of the PagedList and can lead to massive enumerations.

- EDIT -
, Count(), ids.Distinct(int) ColorService.GetColor() .

+3
2

1) PagedList - , , , . , - - "" , .

2) ToList() , , ?

3) GetColors() , , ?

, GetColors, PagedList .

EDIT: " " Count() - IList IList<T>. , Count IEnumerable. , ToList() , , , , .

+4

, IQueryable<T>, .AsQueryable() IEnumerable<T>, . .Skip() .Take() - [your enumerable].Skip(20).Take(10) - 3 10. :

public static IEnumerable<T> GetPage<T>(
    this IEnumerable<T> source,
    int pageIndex, int pageSize)
{
    return source.Skip(pageIndex * pageSize).Take(pageSize);
}

[your enumerable].GetPage(3, 10).

0

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


All Articles