Bulk Inserts

You can use the ExecuteBulkScalar method to insert multiple SmartObject records as a batch.

Copy

Bulk insert data using a DataTable

using(serverName.Connection) {
 // get an object representing the SmartObject definition, the "Regions" SmartObject in this case
 SmartObject regionSmO = serverName.GetSmartObject("Regions");
 regionSmO.MethodToExecute = "Create"; // set which method to call

 using(DataTable inputDataTable = regionSmO.GetInputTable(regionSmO.MethodToExecute)) // create a datatable of the data in the Region SmartObject
  {
   // loop through the first 100 records in the SmartObject and create a new row in the datatable per record
   for (int i = 1; i <= 100; i++) {
    DataRow newRow = inputDataTable.NewRow();
    newRow["ID"] = DBNull.Value;
    newRow["Name"] = string.Concat("Region Name: ", i);
    inputDataTable.Rows.Add(newRow);
   }
   // then bulk write the data to the datatable
   serverName.ExecuteBulkScalar(regionSmO, inputDataTable);
  }
}
Copy

Bulk insert data using a SmartObject List

//This snippet does the same at the first one except using a SmartObjectList

using(serverName.Connection) {
 SmartObject regionSmO = serverName.GetSmartObject("Regions");
 regionSmO.MethodToExecute = "Create";

 using(SmartObjectList inputList = new SmartObjectList()) {
  for (int i = 1; i <= 100; i++) {
   SmartObject newSmartObject = (SmartObject) regionSmO.DeepClone();
   newSmartObject.Properties["ID"].Value = null;
   newSmartObject.Properties["Name"].Value = string.Concat("Region Name: ", i);

   inputList.SmartObjectsList.Add(newSmartObject);
  }

  serverName.ExecuteBulkScalar(regionSmO, inputList);
 }
}