开发者

How to get a block of data from an IEnumerable

开发者 https://www.devze.com 2023-03-17 21:49 出处:网络
I need to get a block of data from an IEnumerable. I found a solution but I want to now if there is a more efficient solution. This is my code:

I need to get a block of data from an IEnumerable. I found a solution but I want to now if there is a more efficient solution. This is my code: ...

foreach (var item in po开发者_JAVA技巧coListToInsert)
{
   var pd = PetaPoco.Database.PocoData.ForType(pocoListToInsert.First().GetType());
   maxRecords = maxParam / pd.Columns.Count;
   if (list.Count < maxRecords)
      list.Add(item);
   else if (list.Count == maxRecords || item == lastRecord)
   {
      Insert(pd.TableInfo.TableName, pd.TableInfo.PrimaryKey, true, pocoListToInsert);
      list.Clear();
   }
} 


Absolutely don't understand you, but maybe LINQ method Skip and Take will be useful for you


Write a linq query that produces the data you want, and end it with .ToList()

0

精彩评论

暂无评论...
验证码 换一张
取 消