Skip to main content
.NET 6.0+

XPObjectSpace.Session Property

Provides access to a Session that is used to load and save persistent objects.

Namespace: DevExpress.ExpressApp.Xpo

Assembly: DevExpress.ExpressApp.Xpo.v24.1.dll

NuGet Package: DevExpress.ExpressApp.Xpo

Declaration

public Session Session { get; }

Property Value

Type Description
Session

A DevExpress.Xpo.Session object which is used by the current Object Space to load and save persistent objects.

Remarks

In XAF, you can use either XPO or Entity Framework as a data layer. To interact with data in terms of persistent objects on a level independent from the data layer that is currently used by the application, an Object Space is used. The Object Space of the XPObjectSpace type is wrapper of the XPO Session. When you use members of XPObjectSpace to retrieve, access and manipulate with data, the Object Space actually uses its Session instance. This property provides access to the Session used by the current Object Space. So, you are not limited to using the Session members directly. The Session object represents a cache of the persistent objects that have been instantiated during data manipulations with a data store. Actually, XAF uses a UnitOfWork that inherits the base functionality from the Session class, but provides a useful capability. When working with Sessions, you need to save each persistent object individually. While working with Units of Work, all the changes made to persistent objects are automatically saved to the database by making a single method call (see BaseObjectSpace.CommitChanges). This happens because it tracks every change to every persistent object. For details, refer to the Session and Unit of Work topics from the XPO documentation.

The example below demonstrates how to prefetch all associated DemoTask objects when the Contact List View is shown in Client mode.

using System.Collections;
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Xpo;
// ...
public class PrefetchTasksController : ObjectViewController<ListView, MainDemo.Module.BusinessObjects.Contact> {
    protected override void OnActivated() {
        base.OnActivated();
        IEnumerable toPrefetch = View.CollectionSource.Collection as IEnumerable;
        if(toPrefetch != null) {
            DevExpress.Xpo.Session session = ((XPObjectSpace)ObjectSpace).Session;
            session.PreFetch(session.GetClassInfo(View.ObjectTypeInfo.Type), toPrefetch, "Tasks");
        }
    }
}

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Session property.

Note

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.

See Also