Skip to main content
.NET Framework 4.5.2+

How to: Map to Custom Tables (Views) and Columns

By default, XPO automatically designates database tables (views) and column names for objects. However, you can override the default mapping with the help of the PersistentAttribute. When applied to a class definition, the attribute’s parameter specifies a table or view name. When applied to a property or field definition, the parameter specifies a column name.

In the example below, class Contact will be stored in the T_CONTACT table, and property LastName will be stored in the ContactLastName column.

[Persistent("T_CONTACT")]
public class Contact: XPObject {
    string lastName = "";
    [Persistent("ContactLastName")]
    public string LastName {
        get { return lastName; }
        set { SetPropertyValue<string>(nameof(LastName), ref lastName, value); }
    }
}
See Also