[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
[Collapse]eXpressApp Framework
 [Expand]Getting Started
  [Expand]Application Solution Components
  [Collapse]Business Model Design
    Business Model Design Basics
    Built-in Business Classes for Most Popular Scenarios
   [Expand]Business Model Design with Entity Framework
   [Expand]Business Model Design with XPO
    Non-Persistent Objects
    PropertyChanged Event in Business Classes
   [Expand]Data Types Supported by built-in Editors
    Mapping Complex Types to the Database
   [Expand]Types Info Subsystem
    Connect an XAF Application to a Database Provider
    Data Annotations in Data Model
    Create and Update the Application's Database
  [Expand]Application Model
  [Expand]UI Construction
  [Expand]Controllers and Actions
  [Expand]Data Manipulation and Business Logic
  [Expand]Security System
  [Expand]System Module
  [Expand]Extra Modules
  [Expand]Debugging, Testing and Error Handling
  [Expand]Application Life Cycle
 [Expand]Design-Time Features
 [Expand]Task-Based Help
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Non-Persistent Objects

A non-persistent class is a type of business class. XAF generates a UI for this class but does not bind it to an application's database table. You can use this class to display a List or Detail View with temporary data generated in code or loaded from storage. You can also use it to display an empty View (dialog) and process the user's input.

Expanded Important Notes

Expanded Basic Non-Persistent Class Implementation

Declare a regular class in the module project and decorate it with the DomainComponentAttribute to implement a non-persistent class.

XAF automatically registers the class with this attribute in the Types Info Subsystem and adds it to the Application Model. Rebuild the solution and open the Model Editor to ensure that XAF added the class to the BOModel node and created the corresponding List and Detail Views.

XAF can display this MyNonPersistentObject's Detail View in a PopupWindowShowAction's popup dialog (see the Add an Action that Displays a Pop-up Window topic).

You can also use the ActionAttribute to show a non-persistent object's popup. For this purpose, apply this attribute to a business class' method that takes a non-persistent type parameter.


Expanded Non-Persistent Object Space

NonPersistentObjectSpace is an Object Space used to manage non-persistent object instances in your application. You can create, read or update non-persistent object instances from code if the XafApplication object supports this Object Space type. To support this Object Space type, add the following code to the overridden CreateDefaultObjectSpaceProvider method in the WinApplication.cs (WinApplication.vb), WebApplication.cs (WebApplication.vb) and/or MobileApplication.cs (MobileApplication.vb) file (in addition to the existing XPObjectSpaceProvider or EFObjectSpaceProvider registration).

Note that the Solution Wizard adds the code above automatically.

XAF uses the first registered Object Space Provider for the following purposes:

Ensure that NonPersistentObjectSpaceProvider is not the first registered Provider in your application.


The NonPersistentObjectSpace cannot handle persistent objects. Create an additional Object Space for the persistent object type and add this Object Space to the NonPersistentObjectSpace.AdditionalObjectSpaces collection to allow processing persistent objects. Refer to the How to: Show Persistent Objects in a Non-Persistent Object's View topic for more information.

The NonPersistentObjectSpace class exposes events that occur when the Object Space loads non-persistent objects. You can handle the following events to supply data to non-persistent objects:

You can use the New, Delete and Save Actions to modify loaded non-persistent objects. The NonPersistentObjectSpace.ModifiedObjects property provides access to modified objects. Use the XafApplication.CreateObjectSpace method to create an Object Space and manage non-persistent objects in your code (for example, in Controller's code):


Expanded Key Property

In XAF ASP.NET and Mobile applications, business objects should have a key property to be correctly displayed in List Views.

In ASP.NET applications, each ASPxGridView control's row should have a unique key. It is required for select, filter, sort and group operations and the standard XAF functionality that depends on them.

In Mobile applications, the key value is included in requests sent by a client application to receive a non-persistent object (for example, when showing a Detail View from a List View). Handle the NonPersistentObjectSpace.ObjectByKeyGetting event to pass an appropriate object to the client application.

Use the KeyAttribute to declare a key property. The BrowsableAttribute allows you to hide this property from UI. The following code snippet demonstrates how to declare the key property in the non-persistent class:


Use the Key attribute from the DevExpress.ExpressApp.Data namespace only (not from the System.ComponentModel.DataAnnotations or DevExpress.Xpo namespaces).

You can allow users to open a specific non-persistent object instance from the Navigation:

  1. Add an item to the navigation. Set its IModelNavigationItem.View property to the identifier of the non-persistent object's DetailView and the IModelNavigationItem.ObjectKey to an arbitrary integer value.

  2. Create a WindowController descendant. In the NonPersistentObjectSpace.ObjectByKeyGetting event handler, get an object instance whose key value coincides with the Navigation Item's ObjectKey property value in the Model Editor.

Example: How to: Display a Non-Persistent Object's Detail View from the Navigation

Expanded INotifyPropertyChanged Support

Implement the INotifyPropertyChanged interface in your non-persistent class to use XAF features that track and process property value changes (for example, Conditional Appearance). Call the OnPropertyChanged method from the property's setter to trigger the PropertyChanged event. The Object Space handles this event internally. The PropertyChanged event triggers the IObjectSpace.ObjectChanged event.

Example: How to: Perform CRUD Operations with Non-Persistent Objects | PropertyChanged Event in Business Classes

Expanded IXafEntityObject and IObjectSpaceLink Support

Implement the IXafEntityObject interface to add custom business logic to the non-persistent class code. This interface declares methods that are called when the Object Space creates, loads, or saves an object. You can also implement the IObjectSpaceLink interface and use the Object Space the IObjectSpaceLink.ObjectSpace property returns. This allows you to query other objects in the same Object Space.

Example: How to: Perform CRUD Operations with Non-Persistent Objects

Expanded Non-Persistent Object Template

You can use a Visual Studio template to create a non-persistent class. For this purpose, open the Template Gallery, switch to the XAF category and choose the XAF Business Object | Non-Persistent Object item. The added class can be used in different complex scenarios listed in this topic.

This non-persistent class includes the IXafEntityObject, IObjectSpaceLink and INotifyPropertyChanged interface implementations and an integer type key property.

Expanded See Also

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