What should we do if we have a batch that with more than 100 items. The simples’ solution is to create groups of chunks of 100 items and execute and execute them in parallel. In the next part of the post we will see how we can create chunks of items from a list:
List<Foo> items = new List<Foo>();
….
int chunkSize = 100;
List<List<Foo>> chunks = new List<List<Foo>>();
int index = 0;
int itemsCount = items.Count;
while( index < itemsCount )
{
int count = itemsCount > chunkSize
? itemsCount
: index;
Chunks.Add( items.GetRange( index, count));
}
After this step if we need to execute the update command over the table context we can do this very easily:foreach( var chunk in chunks )
{
// execute the update command using the Save command.
}
In this post we saw how we can create chunks of items to be able to execute different command on them. If we don’t do this step we will get error when we will try, for example, to update 101 items using only a batch command.
0 comments:
Post a Comment