Saving Multiple Objects¶
This API stores multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which saves two objects in the Person
data table:
IList<Dictionary<string, object>> persons = new List<Dictionary<string, object>>(); Dictionary<string, object> person1 = new Dictionary<string, object>(); person1[ "age" ] = 24; person1[ "name" ] = "Joe"; persons.Add( person1 ); Dictionary<string, object> person2 = new Dictionary<string, object>(); person2[ "age" ] = 34; person2[ "name" ] = "Betty"; persons.Add( person2 ); AsyncCallback<object> bulkCreateCallback = new AsyncCallback<object>( result => { System.Console.WriteLine( "Objects have been saved in the database" ); }, error => { System.Console.WriteLine( "Server returned an error " + error.Message ); } ); Backendless.Data.Of( "Person" ).Create( persons, bulkCreateCallback );
The result of running the sample above is two objects saved in the database:
Blocking Method¶
IList<string> Backendless.Data.Of( "TABLE-NAME" ).Create( IList<Dictionary<string, object>> objects );
public IList<string> Backendless.Data.Of<E>().Create( IList<E> objects );
Non-Blocking API¶
void Backendless.Data.Of( "TABLE-NAME" ).Create( IList<Dictionary<string, object>> objects, AsyncCallback<IList<string>> responder )
public void Backendless.Data.Of<E>().Create( IList<E> objects, AsyncCallback<IList<string>> responder )
where:
Argument | Description |
---|---|
TABLE-NAME |
Name of the table where the objects will be saved. |
E |
A .NET class of the data objects to save. |
objects |
A collection of objects to store in the database. |
responder |
a responder object which will receive a callback when the method successfully saves the objects or if an error occurs. Applies to the non-blocking method only. |
Return Value¶
The API returns a collection of object IDs for the objects created in the database. The order of the objectId
values in the response matches the order of the objects in the request..
The Backendless server implementation enforces the following rules:
- All objects in the request must be of the same type.
- Objects in the request may have different set of properties. If a column does not exist for a property, Backendless will dynamically create it, if the Dynamic Schema Definition configuration is enabled.
- Objects in the request may have a unique
objectId
value that is not used in the database. - Maximum number of objects in a single request is 100 for Backendless Cloud. It is configurable for Backendless Pro and Managed Backendless.
- A request will be rejected by the server, if there is no
Create
permission granted to the user identity/roles associated with the request.