[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Collapse]eXpress Persistent Objects
 [Expand]Product Information
 [Expand]Getting Started
 [Expand]Feature Center
   Basics of Creating Persistent Objects for Existing Data Tables
   Creating a Persistent Object
   Creating a Session
   Creating an XPCollection
   Custom Collection Types
   Deferred and Immediate Object Deletion
   Explicit Units of Work
   Filtering Basics
   Generating Persistent Objects for Existing Data Tables
   How to: Add Persistence to an Existing Hierarchy by Changing the Base Inheritance
   How to: Add Persistence to an Existing Hierarchy by Using Session-less Persistent Objects
   How to: Connect to a Data Store
   Inheritance Mapping
   Nested Units of Work
   NULL Value Handling Specifics
   Optimistic Concurrency Control
   Pageable Collections
   Property Descriptors
   Relationships Between Objects
   Saving Persistent Objects
   Simplified Criteria Syntax
   Simplified Property Syntax
   Sorting Basics
   Using Explicit Transactions
   Using Transactions
   Value Converters
   Working with Sessions
   XPCollection Concepts
   XPDataView Concepts
   XPO Classes Comparison
   XPView Concepts
 [Expand]Design-Time Features
 [Expand]Member Tables
 [Expand]API Reference
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

How to: Add Persistence to an Existing Hierarchy by Changing the Base Inheritance

Changing the base inheritance of classes requires the IXPObject and IComparable interfaces to be implemented. Compared to the other option of adding persistence to an existing class hierarchy which is discussed in the How to: Add Persistence to an Existing Hierarchy by Using Session-less Persistent Objects topic, changing the base inheritance of classes represents a more flexible technique for manipulating persistence objects (such as handling the object's initialization, loading, saving or deletion) and extending their functionality (such as adding collection properties).

Below is a step-by-step guide as to what you need to do.

Expanded Changing the Base Inheritance

Expanded Providing a Session-Specific Constructor

Session-specific constructor declarations are required. The session and classInfo variables are initialized here for future use by the corresponding properties (see IXPSimpleObject implementation below). Additional construction logic can be implemented in the PersistentBase.AfterConstruction method.

Expanded Implementing an Object Identity Value

To distinguish between the states of persistent objects stored in a database, an object identity value should be used. It's used to address a specific object's state. In the following code example one possible implementation of identity values is shown. In a database it will be represented by an auto-generated key field of the integer type.

Expanded Implementing General Persistent Object Manipulation

In order to manipulate persistent objects, the IXPSimpleObject and DevExpress.Xpo.IXPObjectWithChangedEvent events should be implemented. Whenever changes to the object are made, the IXPObjectWithChangedEvent.Changed event should be fired. The type of changes are specified by the ObjectChangeEventArgs instance as shown below.

Expanded Implementing Persistent Object Comparisons

To enable object comparisons, the IComparable interface should be implemented, this is required to implement sorting. The following code example shows how to do this.

Expanded Handling Changes in Persistent Objects

To perform additional housekeeping after initializing, saving or deleting an object, an IXPObject interface should be implemented. The IsLoading property indicates whether the object is completely loaded.

Expanded Providing Lookup Editors Support

To provide support for lookup editors, add This property implementation as shown in the following code example.

Expanded Adding Collection Properties

To implement collection properties, the following code can be used. Note that the Reload method clears the collection's contents (see implementation above).

Expanded Implementing the IObjectLayerProvider interface

The following example demonstrates how to provide access to an Object Access Layer, which the current Session uses to retrieve and update object data in a data store. This property is required for internal purposes.

Expanded See Also

Is this topic helpful?​​​​​​​