The requested page is not available for the requested platform. You are viewing the content for .NET Framework 4.5.2+ platform.
.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET Core 3.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.v19.2.dll

Declaration

public Session Session { get; }
Public ReadOnly Property Session As Session
public Session Session { get; }
Public ReadOnly Property Session As Session
public Session Session { get; }
Public ReadOnly Property Session As Session

Property Value

Type Description
Session

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

Property Value

Type Description
Session

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

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");
        }
    }
}
See Also