Back to Devexpress

XPInstantFeedbackSource.DismissSession Event

xpo-devexpress-dot-xpo-dot-xpinstantfeedbacksource-8180d240.md

latest7.6 KB
Original Source

XPInstantFeedbackSource.DismissSession Event

Occurs when the XPInstantFeedbackSource no longer needs the Session it used to retrieve objects from the data store.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public event EventHandler<ResolveSessionEventArgs> DismissSession
vb
Public Event DismissSession As EventHandler(Of ResolveSessionEventArgs)

Event Data

The DismissSession event's data class is ResolveSessionEventArgs. The following properties provide information specific to this event:

PropertyDescription
SessionSpecifies the session to be used to load and save persistent objects.

Remarks

Handle this event to dispose of the Session manually created in the XPInstantFeedbackSource.ResolveSession event handler. You can also access the object you have assigned to the ResolveSessionEventArgs.Tag field in the ResolveSession event handler. If you did not handle the XPInstantFeedbackSource.ResolveSession event, there is generally no need to handle the DismissSession event.

Example

This example demonstrates how to initialize a XPInstantFeedbackSource, to retrieve data from a “Person.Contact” data table (included in the AdventureWorks database shipped with Microsoft SQL Server). The Person_Contact persistent class is declared, and mapped to the “Person.Contact” data table, using the PersistentAttribute attribute. Then, this class is used as a parameter in the XPInstantFeedbackSource constructor.

csharp
using DevExpress.Xpo;
using DevExpress.Xpo.DB;
using DevExpress.Data.Filtering;

// The persistent class describing the "Person.Contact" table 
// from the AdventureWorks SQL database
[Persistent("Person.Contact")]
public class Person_Contact : XPLiteObject {        
    [Key]
    public System.Int32 ContactID {
        get { return fContactID; }
        set { SetPropertyValue(nameof(ContactID), ref fContactID, value); }
    }
    System.Int32 fContactID;

    public string FirstName {
        get { return fFirstName; }
        set { SetPropertyValue(nameof(FirstName), ref fFirstName, value); }
    }
    string fFirstName;

    public string LastName {
        get { return fLastName; }
        set { SetPropertyValue(nameof(LastName), ref fLastName, value); }
    }
    string fLastName;

    //...
}
public partial class Form1 : Form {
    //...
    public Form1() {
        // ...
        // Create a filter that selects records where last names start with 'A'     
        CriteriaOperator criteria = CriteriaOperator.Parse("[LastName] LIKE ?", "A%");
        // Specify the properties that will be available for binding
        string displayableProperties = "FirstName;LastName";    
        // Initialize an XPInstantFeedbackSource data source 
        // supplying data from the Person.Contact data table     
        XPInstantFeedbackSource instantDS = new XPInstantFeedbackSource(
            typeof(Person_Contact), displayableProperties, criteria);
        // Handle the ResolveSession event, 
        // to provide a Session to the XPInstantFeedbackSource
        instantDS.ResolveSession += instantDS_ResolveSession;
        // Handle the DismissSession event, to dispose of the Session
        instantDS.DismissSession += instantDS_DismissSession;
        //...
    }
    void instantDS_ResolveSession(object sender, ResolveSessionEventArgs e) {
        Session session = new Session();
        session.ConnectionString = @"Integrated Security=SSPI;Pooling=false;
            Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase";
        session.Connect();
        e.Session = session;
    }
    void instantDS_DismissSession(object sender, ResolveSessionEventArgs e) {
        IDisposable session = e.Session as IDisposable;
        if(session != null) {
            session.Dispose();
        }
    }
}
vb
Imports Microsoft.VisualBasic
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB
Imports DevExpress.Data.Filtering

' The persistent class describing the "Person.Contact" table 
' from the AdventureWorks SQL database
<Persistent("Person.Contact")> _
Public Class Person_Contact
    Inherits XPLiteObject
    <Key> _
    Public Property ContactID() As System.Int32
        Get
            Return fContactID
        End Get
        Set(ByVal value as System.Int32)
            SetPropertyValue(NameOf(ContactID), fContactID, value)
        End Set
    End Property
    Private fContactID As System.Int32

    Public Property FirstName() As String
        Get
            Return fFirstName
        End Get
        Set(ByVal value as String)
            SetPropertyValue(NameOf(FirstName), fFirstName, value)
        End Set
    End Property
    Private fFirstName As String

    Public Property LastName() As String
        Get
            Return fLastName
        End Get
        Set(ByVal value as String)
            SetPropertyValue(NameOf(LastName), fLastName, value)
        End Set
    End Property
    Private fLastName As String

    '...
End Class
Partial Public Class Form1
    Inherits Form
    '...
    Public Sub New()
        ' ...
        ' Create a filter that selects records where last names start with 'A'     
        Dim criteria As CriteriaOperator = CriteriaOperator.Parse("[LastName] LIKE ?", "A%")
        ' Specify the properties that will be available for binding
        Dim displayableProperties As String = "FirstName;LastName"
        ' Initialize an XPInstantFeedbackSource data source 
        ' supplying data from the Person.Contact data table     
        Dim instantDS As New XPInstantFeedbackSource( _
        GetType(Person_Contact), displayableProperties, criteria)
        ' Handle the ResolveSession event, 
        ' to provide a Session to the XPInstantFeedbackSource
        AddHandler instantDS.ResolveSession, AddressOf instantDS_ResolveSession
        ' Handle the DismissSession event, to dispose of the Session
        AddHandler instantDS.DismissSession, AddressOf instantDS_DismissSession
        '...
    End Sub
    Private Sub instantDS_ResolveSession(ByVal sender As Object, ByVal e As ResolveSessionEventArgs)
        Dim session As New Session()
        session.ConnectionString = "Integrated Security=SSPI;Pooling=false;" & _
        "Data Source=.\SQLEXPRESS;Initial Catalog=MyDatabase"
        session.Connect()
        e.Session = session
    End Sub
    Private Sub instantDS_DismissSession(ByVal sender As Object, ByVal e As ResolveSessionEventArgs)
        Dim session As IDisposable = TryCast(e.Session, IDisposable)
        If session IsNot Nothing Then
            session.Dispose()
        End If
    End Sub
End Class

See Also

XPInstantFeedbackSource Class

XPInstantFeedbackSource Members

DevExpress.Xpo Namespace