[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]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Collapse]eXpressApp Framework
 [Expand]Fundamentals
 [Expand]Getting Started
 [Expand]Concepts
 [Expand]Design-Time Features
 [Expand]Deployment
 [Collapse]Task-Based Help
  [Collapse]Business Model Design
   [Expand]Common Tasks
   [Expand]Entity Framework (EF)
   [Expand]eXpress Persistent Objects (XPO)
   [Collapse]Non-Persistent Objects
     How to: Display a List of Non-Persistent Objects in a Popup Dialog
     How to: Display a Non-Persistent Object's Detail View from the Navigation
     How to: Display a Non-Persistent Object's List View from the Navigation
     How to: Display Non-Persistent Objects in a Report
     How to: Perform CRUD Operations with Non-Persistent Objects
     How to: Show Persistent Objects in a Non-Persistent Object's View
  [Expand]Application Model
  [Expand]Actions
  [Expand]Navigation
  [Expand]Views
  [Expand]List Editors
  [Expand]Property Editors
  [Expand]Templates
  [Expand]Filtering
  [Expand]Reporting
  [Expand]Dashboards
  [Expand]Scheduler and Notifications
  [Expand]Maps Module
  [Expand]Security
  [Expand]Workflow
  [Expand]Localization
  [Expand]Testing
  [Expand]Miscellaneous UI Customizations
  Frequently Asked Questions (FAQ)
 [Expand]API Reference
[Expand]eXpress Persistent Objects
[Expand]CodeRush
[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: Show Persistent Objects in a Non-Persistent Object's View

This topic describes how to declare a persistent type reference or collection property in a non-persistent class and display it in the user interface, and optionally assign a default value to it.

Expanded Persistent Reference Property

Consider the following non-persistent class:

Note

The INotifyPropertyChanged, IXafEntityObject and IObjectSpaceLink interface implementations were omitted in this example. However, it is recommended to support these interfaces in real-world applications (see PropertyChanged Event in Business Classes and Non-Persistent Objects).

Tip

Use the approach demonstrated in the How to: Perform CRUD Operations with Non-Persistent Objects topic to support saving and loading non-persistent objects from a local cache.

Here, Person is a persistent class from the Business Class Library (for Entity Framework or XPO). Refer to the Add a Class from the Business Class Library (EF) or Add a Class from the Business Class Library (XPO) topic to learn how to add a class from this library. Also, you can use your custom business class instead of Person.

At this stage, the Detail View invoked when creating a new NonPersistentObject, displays the lookup editor for the Owner property. However, the lookup is empty, and you cannot choose any existing Person.

The NonPersistentObjectSpace Object Space created for the current View cannot handle the Person persistent object. You should create an additional Object Space for the Person type and add it to the NonPersistentObjectSpace.AdditionalObjectSpaces collection. You can do this in a module by subscribing to the XafApplication.ObjectSpaceCreated event as follows:

The result is demonstrated below.

Expanded Persistent Collection

You can add the Owners collection instead of the Owner reference property:

Users can add and remove Owners via the Link and Unlink Actions after adding the code from the previous section.

Expanded Initialize Persistent Property Values

Implement the IObjectSpaceLink interface in your non-persistent class and use the IObjectSpace.GetObjects method to get required persistent objects.

If you create a new NonPersistentObject in UI, its Owner property and Owner collection are initialized:

Expanded Important Notes

Note the following if your non-persistent class contains persistent properties and implements IObjectSpaceLink.

When loading such an object from a separate NonPersistentObjectSpace, you get the same object instance linking to the initial Object Space via IObjectSpaceLink.ObjectSpace. If this behavior is unwanted, you can update the Object Space in the NonPersistentObjectSpace.ObjectsGetting event handler. Modify the NonPersistentModule class demonstrated in the Persistent Reference Property section as follows:

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