Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving multiple objects at once in parse.com

I am trying to save multiple objects at once in a ASP.NET project to Parse.com backend. I have tried to save it one by one but in some cases it returns me error in the middle of saving process. So some of my objects are being saved some are not. Here is the code I am using:

ParseObject gameScore
foreach (DataRow row in dataTable.Rows) //imagine here I am saving 1000 objects
{
      gameScore = new ParseObject("SALON");
      gameScore["NAME"] = "NAMETEMP";
      await gameScore.SaveAsync();
}
like image 570
birdcage Avatar asked Mar 19 '23 03:03

birdcage


1 Answers

Rather than make individual requests to save each object, try using the saveAll method which will batch them:

List<ParseObject> scores = new List<ParseObject>();
foreach (DataRow row in dataTable.Rows) //imagine here I am saving 1000 objects
{
      gameScore = new ParseObject("SALON");
      gameScore["NAME"] = "NAMETEMP";
      scores.Add(gameScore);
}
await ParseObject.SaveAllAsync(scores);
like image 54
Fosco Avatar answered Mar 24 '23 10:03

Fosco