expressappframework-114516-business-model-design-orm-non-persistent-objects-how-to-display-non-persistent-objects-in-a-report.md
This topic describes how to create a report based on non-persistent data. Use this approach to analyze and report data obtained from runtime calculations, stored procedures, arbitrary SQL queries, or third-party services.
Declare a non-persistent class (for example, MyNonPersistentObject), and decorate it with the DomainComponent and VisibleInReports attributes.
Create a report for the MyNonPersistentObject data type. You can add a predefined static report in Visual Studio or create a report at runtime.
In the Application Builder code, handle the NonPersistentObjectSpace.ObjectsGetting event as shown below:
File : MySolution.Blazor.Server\Startup.cs, MySolution.Win\Startup.cs
using System.ComponentModel;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Core;
// ...
// Handle the `NonPersistentObjectSpace.ObjectsGetting` event.
builder.ObjectSpaceProviders.Events.OnObjectSpaceCreated = context => {
if (context.ObjectSpace is NonPersistentObjectSpace nonPersistentObjectSpace) {
nonPersistentObjectSpace.ObjectsGetting += NonPersistentObjectSpace_ObjectsGetting;
}
};
// ...
private static void NonPersistentObjectSpace_ObjectsGetting(object sender, ObjectsGettingEventArgs e) {
// In the event handler, populate the `e.Objects` collection
// with non-persistent objects of the required type.
if (e.ObjectType == typeof(MyNonPersistentObject)) {
BindingList<MyNonPersistentObject> objects = new BindingList<MyNonPersistentObject>();
for (int i = 1; i < 10; i++) {
objects.Add(new MyNonPersistentObject() { Name = string.Format("Object {0}", i) });
}
e.Objects = objects;
}
}
// ...
In the module project, implement the IObjectSpaceCustomizer service as shown below:
Register your IObjectSpaceCustomizer service implementation in the Starup.cs file of the Blazor and WinForms applications. Use the TryAddEnumerable method to register these services:
The following image demonstrates the result: