public class XPObjectSpace :
Public Class XPObjectSpace
When an XAF application uses XPO as an ORM layer, an Object Space of the XPObjectSpace class is created. This class is a wrapper over of the Unit of Work which is used in XPO as a cache for persistent objects. To access the UnitOfWork used by the current Object Space, use the XPObjectSpace.Session property. The Object Space uses its UnitOfWork to create, manage and delete persistent objects.
The UnitofWork tracks every change to every persistent object. All the changes made to persistent objects are automatically saved to the database by making a single method call (see BaseObjectSpace.CommitChanges). For details, refer to the Session and Unit of Work topics from the XPO documentation. To be sure that changes made to a persistent object's properties are cached and then committed with other changes, call the SetPropertyValue method with three parameters in the property setters. This is the recommended way to implement persistent properties if you want changes to be recognized automatically in Units of Work with which XAF's Object Spaces work. If you need to track a custom object change, use the BaseObjectSpace.SetModified method.
XPObjectSpace works with collections of the XPCollection type when it is required to load all required objects to a client at once, and with the XPServerCollectionSource collection type when loading objects in small portions on demand.
When you need to create a new Object Space, use the XafApplication.CreateObjectSpace method. It will create an Object Space of the XPObjectSpace type if the default Object Space Provider is of the XPObjectSpaceProvider type (see the CreateDefaultObjectSpaceProvider method implementation of your WinApplication descendant in your application).
To learn more about Object Spaces, refer to the BaseObjectSpace class description.