Skip to content

Class to Table Mapping

When you use custom classes in your application for data persistence, Backendless maps the database table names to the names of the classes. For example, the following code is automatically mapped to the Person table:

namespace com.sample
{
  public class Person
  {
    public string name { get; set; }
    public int age { get; set; }
  }
}

The Person table in the Backendless database:

person-table

When the name of the class is different than the name of the corresponding table in the database, it is necessary to customize the mapping. This can be achieved with the following API:

Backendless.Data.MapTableToType( string YOUR-TABLE, Type type )

where:

Argument                Description
type reference to a class to map to the table.

The API is not necessary if the class name is the same as the table name. The only exception to this rule is when your application retrieves related objects using the "Custom Class" approach. In this case, if application should establish mappings between client-side classes and the related (children) tables. For example, consider the following schema:

Order (parent) table:

parent-order-table

OrderItem (child) table:

child-orderitem-table

If any related OrderItem objects are retrieved along the parent Order object (via auto-load or single-step relation retrieval), then the application must establish a mapping for the OrderItem table before the data is retrieved.

Backendless.Data.MapTableToType( "OrderItem", typeof( OrderItem ) )