我在我的項目中使用Troy Goode's paged List。
通常你只需要給它一個IEnumerable,一個startindex和一個項目計數,它都可以工作。
但是現在我想如下給它一個IEnumerable我產生:我如何使我的IEnumerable與PagedList工作
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);
}
}
- 編輯 - 的pagedList工作,但要求我所有的物體色彩的產量,而不是隻分頁的。這個偏離路線失敗了PagedList的整個使用,並可能導致大量的枚舉。
- 編輯 -
我想我需要的是實現計數()的方式,所以我可以把它從ids.Distinct(INT),而不是通過ColorService創建的所有對象返回計數。 GetColor()然後計算該列表。
它已經使用IEnumerable並在必要時調用AsQueryable。 – 2009-02-16 11:45:59
d'oh!從頭開始,然後... – 2009-02-16 11:52:29