Data Object¶
Backendless database stores objects in data tables. A persisted object is stored in a language-independent format. For the .NET applications, there are two ways to represent data objects on the client side:
- Data objects can be stored/retrieved as instances of
System.Collections.Generic.Dictionary
. For example, the following code saves an object with properties"name"
and"age"
in the"Person"
table:This approach is referenced as "Dictionary" further in the documentation.Dictionary<String, Object> person = new Dictionary<String, Object>(); person.Add( "name", "Joe" ); person.Add( "age", 25 ); Backendless.Data.Of( "Person" ).Save( person );
or - Data objects can be represented as instances of custom classes mapped to data tables. Object's class does not need to implement any special Backendless interfaces or extend a class from the Backendless SDK. For example, the following code saves an object with properties
"name"
and"age"
in the"Person"
table:This approach is referenced as "Custom Class" further in the documentation.public class Person { // this class uses properties, but you can // also use publish fields public string name { get; set; } public int age { get; set; } } Person person = new Person(); person.name = "Joe"; person.age = 25; Backendless.Data.Of<Person>().Save( person );
There are several requirements imposed on the classes of the objects saved in the Backendless database:
- The class must contain the default, public, no-argument constructor.
- The class must contain either at least one public field or a get/set property.
-
Optional requirement - Backendless automatically assigns a unique ID to every persisted object. If the application needs to have access to the assigned ID, the class must declare the following field:
public string objectId;
-
Optional requirement - in addition to
objectId
, Backendless maintains two other properties for every persisted object -created
andupdated
. The former contains the timestamp when the object was initially created in the Backendless database. The latter is updated every time the object is updated. To get access to these values, the class must declare the following fields:public DateTime created; public DateTime updated;