Skip to main content
A newer version of this page is available. .

Create, Read, Update and Delete Data

  • 2 minutes to read

You can create a business logic in the following places:

  • In Controllers.

    In Controllers, you can declare new and customize existing Actions and handle other Controllers’ events. Once you have obtained or created an Object Space instance (as described in the Object Space topic), you can use it for data manipulation (create, read, update or delete data).

  • In Model (business classes).

    In business classes (model), you can put logic into property getters and setters, implement methods that are triggered automatically when the object is created, loaded, saved, and deleted (see IXafEntityObject) and declare action methods.

    This topic lists article that describe how to implement common data-aware operations in Controllers with the corresponding Object Space methods and events and business classes.

Tasks

CRUD in XPO

When an XAF application uses XPO, an XPObjectSpace is created. Internally, it uses a UnitOfWork to perform create, update and delete with business objects. From an XPObjectSpace, use the XPObjectSpace.Session property to access a UnitOfWork.

When you create a new XPO business object, the XPObjectSpace’s UnitOfWork to passed to the business class constructor. You can access the passed UnitOfWork in a business class via the Session property. Use this UnitOfWork to load and create business objects in business classes according to the XPO documentation: Create-Read-Update-Delete (CRUD).

When a new XPObjectSpace is created, a new UnitOfWork is also created. An XPObjectSpace can create a new UnitOfWork, for example, when the IObjectSpace.Refresh method is called. This UnitOfWork connects to a Data Layer or Object Layer that corresponds to the current ObjectSpaceProvider.

CRUD in EF Core

Inside an EF Core business class, implement the IObjectSpaceLink interface in the class. XAF will automatically assign an Object Space instance to the IObjectSpaceLink.ObjectSpace property. Use the assigned Object Space APIs listed in the above topics to for data manipulation in EF Core business classes.

See Also