The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

PersistentAttribute Class

Indicates that a property, field or class will be stored in a persistent data store and specifies the target column or table name.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v19.1.dll

Declaration

[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface, Inherited = true)]
public sealed class PersistentAttribute : Attribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Interface, Inherited:=True)>
Public NotInheritable Class PersistentAttribute
    Inherits Attribute
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Field | AttributeTargets.Interface | AttributeTargets.Property, Inherited = true)]
public sealed class PersistentAttribute : Attribute
<AttributeUsage(AttributeTargets.Class Or AttributeTargets.Field Or AttributeTargets.Interface Or AttributeTargets.Property, Inherited:=True)>
Public NotInheritable Class PersistentAttribute
    Inherits Attribute

Remarks

Generally, XPO stores only writable properties and public fields. Use the PersistentAttribute whenever you want to force persistence for non-writable or non-public fields (for instance, if you need to store a read-only property value to the database). Use the PersistentAttribute.MapTo parameter to specify the column name for the property or field to persist.

This attribute can also be applied to a class to make it persistent and to map objects of this class to a specific table/view in a data store. Only a single class can be mapped to a specific table/view. Otherwise, an SameTableNameException exception will be raised.

A persistent class, that is a descendant of another persistent class, can be mapped to the table to which its ancestor is mapped using the MapInheritanceAttribute attribute.

To map a class to a table in a specific schema, prefix the table name with the schema name. For example: "MySchema.MyTable". Note that the specified schema name must already exist in the database. Also, some connection providers allow you to specify a common schema name for all classes in the ObjectsOwner field of the connection provider. This field is implemented by SQL Server, SQL Server CE, Oracle, PostreSQL, and DB2 connection providers.

It's also possible to make an object persistent by implementing the IXPSimpleObject or IXPObject interface or by deriving it from the XPBaseObject class or one of its descendants.

Examples

The following example shows different functions of the PersistentAttribute. It is used for: specifying the table name to which the Person class is mapped, specifying the column name to which the FullName property and the mDefaultAddress field are mapped, and to make the private field (mDefaultAddress) persistent.

The PersistentAliasAttribute is used here to allow accessing the persistent mDefaultAddress field in criteria via the read-only DefaultAddress property's name.

using DevExpress.Xpo;

[Persistent("PRSN")]
public class Person : XPLiteObject {

    //...

    [Persistent("NAME")]
    public string FullName {
        get { return GetPropertyValue<string>("FullName"); }
        set { SetPropertyValue<string>("FullName", value); }
    }

    [Persistent("ADR")]
    private string mDefaultAddress;

    [PersistentAlias("mDefaultAddress")]
    public string DefaultAddress {
        get { return mDefaultAddress; }
    }
}

Inheritance

Object
Attribute
PersistentAttribute
See Also