When an XAF application uses the Entity Framework as an ORM layer, an Object Space of the
EFObjectSpace class is created. This class is a wrapper over the ObjectContext, which is a container for in-memory objects in the Entity Framework. To access the Object Context used by the current Object Space, use the EFObjectSpace.ObjectContext property. The Object Space uses its Object Context to create, manage and delete persistent objects.
The Object Context’s ObjectStateManager tracks every change to every simple property of a persistent object. All the changes are automatically saved to the database by making a single call of the ObjectContext.SaveChanges method, which the Object Space performs using the BaseObjectSpace.CommitChanges method. For details, refer to the Entity Framework documentation. To be sure that changes made to a persistent object’s reference properties are tracked, call the BaseObjectSpace.SetModified method after you change such properties in code.
EFObjectSpace works with collections of the DevExpress.ExpressApp.EF.EFCollection type when it is required to load all required objects to a client at once, and with the DevExpress.ExpressApp.EF.EFServerCollection 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 EFObjectSpace type, if the default Object Space Provider is of the EFObjectSpaceProvider 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.
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the EFObjectSpace class.
The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.