Log In
[Expand]Welcome to DevExpress .NET Documentation
[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]Document Server
[Expand]Report 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]Extend Functionality
  [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]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

Non-Persistent Objects

A non-persistent class is a business class, which participates in automatic UI generation, but is not bound to an XAF application's database table using an ORM tool (Entity Framework or XPO). Such a class may be required if you want to display a List or Detail View with temporary data generated in code or loaded from a custom storage; or display an empty View (dialog) and then process the user input.

This topic includes the following sections.


Expanded Basic Implementation of a Non-Persistent Class

In the simplest case, you can declare a regular class in the module project and decorate it with the DomainComponentAttribute.

With this attribute, this class is automatically registered in the Types Info Subsystem and added to the Application Model. You can rebuild the solution and run the Model Editor to ensure that the class is added to the BOModel node and corresponding List and Detail Views are created.

This simple implementation is sufficient if you are going to display the MyNonPersistentObject Detail View in a PopupWindowShowAction's popup dialog (see Add an Action that Displays a Pop-up Window).

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 parameter of the non-persistent type.


Expanded Non-Persistent Object Space

NonPersistentObjectSpace is an Object Space used to manage non-persistent object instances in your application. If you are going to implement a custom code to create, read or update non-persistent object instances, ensure that your XafApplication object supports this type of an Object Space. The following code should be added to the overridden CreateDefaultObjectSpaceProvider method located 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).

Currently, this code is added automatically by the Solution Wizard, but it may be missing if you have created your project using an older version of XAF.

The NonPersistentObjectSpace class exposes events that are triggered when the Object Space loads non-persistent objects. You can handle these events to supply data for non-persistent objects.

The New, Delete and Save Actions are available for non-persistent objects, so users can modify loaded objects. Modified objects are accessible using the NonPersistentObjectSpace.ModifiedObjects property


Expanded Key Property

In XAF ASP.NET applications, business objects should have a key property to be correctly displayed in List Views. The ASPxGridView control requires that each row should have a unique key for the correct operation of many features like selection, filtering, sorting, grouping (and standard XAF functionality that depends on them). A key property is also required if you are going to access a non-persistent object by a key using the NonPersistentObjectSpace.ObjectByKeyGetting event. To declare a key property, use the KeyAttribute. To hide this property from UI, use the BrowsableAttribute.


Do not mix the DevExpress.ExpressApp.Data.Key attribute with similar attributes available in System.ComponentModel.DataAnnotations and DevExpress.Xpo namespaces.

You can allow users to open a specific non-persistent object instance from the Navigation. For this purpose, add an item to the navigation, set the IModelNavigationItem.View to the identifier of the non-persistent object's DetailView and set the IModelNavigationItem.ObjectKey to a certain key value.

Then, create a WindowController descendant and handle the NonPersistentObjectSpace.ObjectByKeyGetting event to supply an instance of the object by a key value specified in the Model Editor.

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

Expanded INotifyPropertyChanged Support

To use XAF features that imply an immediate reaction on property value changes (e.g., Conditional Appearance), implement the INotifyPropertyChanged interface in your non-persistent class.

Call the OnPropertyChanged method from property setters to trigger the PropertyChanged event. Internally, this event is handled by the Object Space. The IObjectSpace.ObjectChanged is triggered when the PropertyChanged event occurs.

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

Expanded IXafEntityObject and IObjectSpaceLink Support

To add certain business logic directly in the non-persistent class object code, implement the IXafEntityObject interface. This interface declares methods called when an object is being created, loaded and saved by the Object Space. You can also implement the IObjectSpaceLink interface and use the Object Space returned by the IObjectSpaceLink.ObjectSpace property to query other objects in the same Object Space.

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

Expanded Non-Persistent Object Template

XAF provides a Visual Studio template for creating a non-persistent class, which can be used in different complex scenarios listed in this topic. To use it, open the Template Gallery, switch to the XAF category and choose the XAF Business Object | Non-Persistent Object item.

The non-persistent class created using this template includes the IXafEntityObject, IObjectSpaceLink and INotifyPropertyChanged interface implementations and the key property of an integer type.

Expanded See Also

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