Saving Single Object¶
Blocking Method¶
Dictionary<string, object> result;
result = Backendless.Data.Of( "TABLE-NAME" ).Save( Dictionary<string, object> );
public E Backendless.Data.Of<E>().Save( E entity );
Non-Blocking API¶
void Backendless.Data.Of( "TABLE-NAME" ).Save( Dictionary<string, object> entity,
AsyncCallback<Dictionary<string, object>> responder )
public void Backendless.Data.Of<E>().Save( E entity, AsyncCallback<E> responder )
where:
Argument | Description |
---|---|
TABLE-NAME |
Name of the table where the object represented by System.Collections.Generic.Dictionary will be saved. |
E |
A .NET class of the data object to save. |
entity |
.NET object to persist, must be of type E or System.Collections.Generic.Dictionary (depending on the method used). |
responder |
a responder object which will receive a callback when the method successfully saves the object or if an error occurs. Applies to the non-blocking method only. |
Return Value¶
The blocking method returns the saved object. The non-blocking call receives the return value through a callback executed on the AsyncCallback
object.
Example¶
Dictionary<string, object> contact = new Dictionary<string, object>();
contact[ "name" ] = "Jack Daniels";
contact[ "age" ] = 147;
contact[ "phone" ] = "777-777-777";
contact[ "title" ] = "Favorites";
// save object synchronously
Dictionary<string, object> savedContact;
savedContact = Backendless.Data.Of( "Contact" ).Save( contact );
// save object asynchronously
AsyncCallback<Dictionary<string, object>> callback;
callback = new AsyncCallback<Dictionary<string, object>>(
result =>
{
// object has been saved
},
fault =>
{
// server reported an error
} );
Backendless.Data.Of( "Contact" ).Save( contact, callback );
Consider the following class.
using System;
namespace com.mbaas
{
public class Contact
{
public String objectId { get; set; }
public String Name { get; set; }
public int Age { get; set; }
public String Phone { get; set; }
public String Title { get; set; }
}
}
Contact contact = new Contact();
contact.Name = "Jack Daniels";
contact.Age = 147;
contact.Phone = "777-777-777";
contact.Title = "Favorites";
// save object synchronously
Contact savedContact = Backendless.Data.Of<Contact>().Save( contact );
// save object asynchronously
AsyncCallback<Contact> callback = new AsyncCallback<Contact>(
result =>
{
// object has been saved
},
fault =>
{
// server reported an error
} );
Backendless.Data.Of<Contact>().Save( contact, callback );