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()
精彩评论