Search This Blog

Thursday, March 3, 2016

How to perform CRUD operations with non-persistent objects using standard XAF forms

This post is about our putting a continuous effort into improving XAF developer usability in scenarios requiring manipulation of non-persistent objects or POCOs. Typical scenarios relying on such non-persistent classes include all sorts of confirmation dialogs, user input forms with parameters, lists with temporary data, analysis and reporting data obtained from dynamic runtime calculations, stored procedures (SP), arbitrary SQL queries or third-party services or anything that needs a standard XAF CRUD UI (and, of course, extra modules), but does not require object state to be eventually persisted to the database.

As you probably know, XAF was primarily designed for automatic UI generation tied to one of the two supported persistence layers or ORM technologies - XPO and Entity Framework. Don't get me wrong here: binding standard XAF forms to temporary non-persistent data was always possible (and there are many standard XAF pieces are implemented with it: logon, change the password, about, validation, notification dialogs, etc.), but the number of supported scenarios was quite limited previously. For instance, a year ago there was no really straightforward way of binding a non-persistent list of objects to a ListView directly. It required creating an intermediate non-persistent class holding a collection of non-persistent objects and then showing its DetailView (learn more on this former approach...).

So that is where NonPersistentObjectSpaceProvider, NonPersistentObjectSpace and its ObjectsGetting event first came to the rescue in v15.1 to simplify the lives of XAF developers (learn more...). The current v15.2 brought it to the next level by allowing standard XAF CRUD commands (the New, Delete and Save Actions) for non-persistent objects. The ModifiedObjects property of the NonPersistentObjectSpace class provides access to all created, deleted and modified objects within its scope, unless the IObjectSpace.CommitChangesIObjectSpace.Refresh or IObjectSpace.Rollback methods are called. Step-by-step instructions for implementing this functionality in your XAF v15.2.4+ project are now provided in the online product documentation:

How to: Perform CRUD Operations with Non-Persistent Objects

And here are a couple of screenshots showing what it can look like in the UI*:

As you can see, it is not much different from what you have for persistent XPO or EF classes, with the only difference being that you manage all "data querying and persistence" yourself. Of course ( and understandably), pure database-related operations and features like "server mode", "data view", etc. will not be usable with non-persistent data by default. Regardless, I will not be surprised if some customers, who sometimes ask us about the possibility of using XAF without any ORM (often for integration with legacy apps or third-party services), will start employing the aforementioned approach (I would still recommend thinking twice about this, though, because for this task this approach appears to be a workaround rather than a straightforward solution). After all, to get an XAF form, you just need a regular class representing your data model structure and now XAF is less concerned with whether it comes from the db or an arbitrary service...

*The same functionality is available in ASP.NET, but there is a small issue in the current version (it should be corrected shortly), so I would not show the web screenshot for now.

No comments:

Post a Comment