Skip to content

Basic Object Retrieval

Backendless supports multiple data search and retrieval operations. These include finding an object by its objectId, finding first or last object in the collection or retrieving the entire persisted collection. Each method is available in both blocking and non-blocking formats:

Retrieving Data Objects

Blocking Methods

Retrieve data objects with the default paging setting from a table:
IList<Dictionary<string, object>> Backendless.Data.Of( "TABLE-NAME" ).Find()
Find first data object in a table. The first data object is the first one saved in the database:
Dictionary<string, object> Backendless.Data.Of( "TABLE-NAME" ).FindFirst()
Find last data object from a table. The last data object is the last one saved in the database:
Dictionary<string, object> Backendless.Data.Of( "TABLE-NAME" ).FindLast()
Find a data object by its objectId:
Dictionary<string, object> Backendless.Data.Of( "TABLE-NAME" ).FindById( string objectId )
Retrieve data objects with the default paging setting from a table. Returned collection will contain objects of type E (the name of the class must match the name of the table):
IList<E> Backendless.Data.Of<E>().Find()
Find first data object of class E. The first data object is the first one saved in the database:
E Backendless.Data.Of<E>().FindFirst()
Find last data object of type E. The last data object is the last one saved in the database:
E Backendless.Data.Of<E>().FindLast()
Find a data object by its objectId:
E Backendless.Data.Of<E>().FindById( string objectId )

Non-blocking Methods

Retrieve data objects with the default paging setting from a table:
public void Backendless.Data.Of( "TABLE-NAME" ).Find( 
                AsyncCallback<IList<Dictionary<string, object>>> callback )
Find first data object in a table. The first data object is the first one saved in the database:
public void Backendless.Data.Of( "TABLE-NAME" ).FindFirst( 
                AsyncCallback<Dictionary<string, object>> callback )
Find last data object in a table. The last data object is the last one saved in the database:
public void Backendless.Data.Of( "TABLE-NAME" ).FindLast( 
                AsyncCallback<Dictionary<string, object>> callback )
Find a data object by its objectId:
public void Backendless.Data.Of( "TABLE-NAME" ).FindById( 
                string objectId, 
                AsyncCallback<Dictionary<string, object>> callback )
Retrieve data objects with the default paging setting from a table. Returned collection will contain objects of type E (the name of the class must match the name of the table):
public void Backendless.Data.Of<E>().Find( AsyncCallback<IList<E>> callback );
Find first data object in a table. The name of the class E must match the name of the table. The first data object is the first one saved in the database:
public void Backendless.Data.Of<E>().FindFirst( AsyncCallback<E> callback )
Find last data object in a table. The name of the class E must match the name of the table. The last data object is the last one saved in the database:
public void Backendless.Data.Of<E>().FindLast( AsyncCallback<E> callback )
Find a data object by its objectId. The name of the class E must match the name of the table:
public void Backendless.Data.Of<E>().FindById( string objectId, 
                                                  AsyncCallback<E> callback )

where:

Argument                Description
TABLE-NAME Name of the table from where the data is retrieved from.
E a .NET class identifying the table where from where the data must be loaded from.
callback a callback object which will receive a callback when the method successfully returns a result or an error. Applies to the non-blocking methods only.

Example

The following code demonstrates various search queries:

Load contacts using default paging

Blocking call

IList<Dictionary<string, object>> result = Backendless.Data.Of( "Contact" ).Find();

Non-blocking call

AsyncCallback<IList<Dictionary<string, object>>> callback;
callback = new AsyncCallback<IList<Dictionary<string, object>>>(
  foundContacts =>
  {
  },
  error =>
  {
    System.Console.WriteLine( "Server returned an error " + error.Message );
  } );
Backendless.Data.Of( "Contact" ).Find( callback );


Find first contact

Blocking call

Dictionary<string, object> firstContact = Backendless.Data.Of( "Contact" ).FindFirst();

Non-blocking call

AsyncCallback<Dictionary<string, object>> callback;
callback = new AsyncCallback<Dictionary<string, object>>(
  foundContacts =>
  {
  },
  error =>
  {
    System.Console.WriteLine( "Server returned an error " + error.Message );
  } );

Backendless.Data.Of( "Contact" ).FindFirst( callback );


Find last contact

Blocking call

Dictionary<string, object> lastContact = Backendless.Data.Of( "Contact" ).FindLast();

Non-blocking call

AsyncCallback<Dictionary<string, object>> callback;
callback = new AsyncCallback<Dictionary<string, object>>(
  foundContacts =>
  {
  },
  error =>
  {
    System.Console.WriteLine( "Server returned an error " + error.Message );
  } );

Backendless.Data.Of( "Contact" ).FindLast( callback );


Find contact by objectId

Blocking call

// Save a contact object first. Once it is saved, we will retrieve it by the assigned objectId
Dictionary<string, object> contact = new Dictionary<string, object>();
contact.Add( "name", "Jack Daniels" );
contact.Add( "age", 147 );
contact.Add( "phone", "777-777-777" );
contact.Add( "title", "Favorites" );

// save object synchronously
Dictionary<string, object> savedContact = Backendless.Data.Of( "Contact" ).Save( contact );

// now retrieve the object using it's objectId
Dictionary<string, object> foundContact = Backendless.Data.Of( "Contact" ).
                                    FindById( (string) savedContact[ "objectId" ] );

Non-blocking call

// Save a contact object first. Once it is saved, we will retrieve it by the assigned objectId
Dictionary<string, object> contact = new Dictionary<string, object>();
contact.Add( "name", "Jack Daniels" );
contact.Add( "age", 147 );
contact.Add( "phone", "777-777-777" );
contact.Add( "title", "Favorites" );

AsyncCallback<Dictionary<string, object>> getObjectCallback = 
new AsyncCallback<Dictionary<string, object>>(
foundContact =>
{
},
error =>
{
  System.Console.WriteLine( "Server returned an error " + error.Message );
} );

AsyncCallback<Dictionary<string, object>> saveObjectCallback = 
new AsyncCallback<Dictionary<string, object>>(
savedContact =>
{
  // now retrieve the object using it's objectId
  Backendless.Data.Of( "Contact" ).FindById( (string) savedContact[ "objectId" ], getObjectCallback );

},
error =>
{
  System.Console.WriteLine( "Server returned an error " + error.Message );
} );

// save object asynchronously
Backendless.Data.Of( "Contact" ).Save( contact, saveObjectCallback );
Consider the following class:
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; }
}
The following code demonstrates various search queries using the class:

Load contacts using default paging

Blocking call

IList<Contact> result = Backendless.Data.Of<Contact>().Find();

Non-blocking call

AsyncCallback<IList<Contact>> getContactsCallback = 
  new AsyncCallback<IList<Contact>>(
    foundContacts =>
    {
    },
    error =>
    {
      System.Console.WriteLine( "Server returned an error " + error.Message );
    } );

Backendless.Data.Of<Contact>().Find( getContactsCallback );


Find first contact

Blocking call

Contact firstContact = Backendless.Data.Of<Contact>().FindFirst();

Non-blocking call

AsyncCallback<Contact> getContactCallback = 
  new AsyncCallback<Contact>(
    foundContact =>
    {
    },
    error =>
    {
      System.Console.WriteLine( "Server returned an error " + error.Message );
    });

Backendless.Data.Of<Contact>().FindFirst( getContactCallback );


Find last contact

Blocking call

Contact lastContact = Backendless.Data.Of<Contact>().FindLast();

Non-blocking call

AsyncCallback<Contact> getContactCallback = 
  new AsyncCallback<Contact>(
    foundContact =>
    {
    },
    error =>
    {
      System.Console.WriteLine( "Server returned an error " + error.Message );
    });

Backendless.Data.Of<Contact>().FindLast( getContactCallback );


Find contact by objectId

Blocking call

// Save a contact object first. Once it is saved, we will retrieve it by assigned objectId
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 );

// now retrieve the object using it's objectId
Contact foundContact = Backendless.Data.Of<Contact>().FindById( savedContact.ObjectId );

Non-blocking call

// Save a contact object first. Once it is saved, we will retrieve it by assigned objectId
Contact contact = new Contact();
contact.Name = "Jack Daniels";
contact.Age = 147;
contact.Phone = "777-777-777";
contact.Title = "Favorites";

AsyncCallback<Contact> loadContactCallback = new AsyncCallback<Contact>(
  foundContact =>
  {
  },
  error =>
  {
    System.Console.WriteLine( "Server returned an error " + error.Message );
  } );

AsyncCallback<Contact> saveContactCallback = new AsyncCallback<Contact>(
  savedContact =>
  {
    Backendless.Data.Of<Contact>().FindById( savedContact.ObjectId );
  },
  error =>
  {
    System.Console.WriteLine( "Server returned an error " + error.Message );
  } );

// save object asynchronously
Backendless.Data.Of<Contact>().Save( contact, saveContactCallback );