Base Persistent Classes
- 2 minutes to read
This topic describes the base persistent classes that can be used in XAF applications when creating a data model with XPO.
The following table lists the base persistent classes you can inherit from when you define persistent business classes:
Persistent Class | Namespace | Supported Concurrency Control | Contains the Auto-Generated Primary Key Property | Supports Deferred Deletion |
---|---|---|---|---|
XPLiteObject | DevExpress.Xpo | None (“Last in wins”) | No | No |
XPBaseObject | DevExpress.Xpo | Optimistic | No | No |
XPCustomObject | DevExpress.Xpo | Optimistic | No | Yes |
XPObject | DevExpress.Xpo | Optimistic | Yes. Integer type. | Yes |
BaseObject | DevExpress.Persistent.BaseImpl | Optimistic | Yes. Guid type. | Yes |
The BaseObject class is used when creating business classes from the XPO Business Object template. It is a feature-rich persistent class that supports the optimistic concurrency control (optimistic locking mechanism).
We recommend using the XPObject class if your business class should use the integer type primary key. This class also supports optimistic concurrency control.
You need to define the primary key property in the business class declaration if you are using classes which do not have the auto-generated primary key property. The following code snippet illustrates this:
using System.ComponentModel;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
//...
[DefaultClassOptions]
public class MyClass : XPLiteObject {
public MyClass(Session session) : base(session) { }
[Key(AutoGenerate = true), Browsable(false)]
public int Oid { get; set; }
string fMyProperty;
public string MyProperty {
get { return fMyProperty; }
set { SetPropertyValue(nameof(MyProperty), ref fMyProperty, value); }
}
}
If you need to consider whether to use a base class that supports the deferred deletion feature, refer to the XPO documentation: Deleting Persistent Objects.
You can implement a custom base persistent class. To learn more, refer to the How to: Implement a Custom Base Persistent Class help topic.