Back to Devexpress

XPServerCollectionSource(Session, Type) Constructor

xpo-devexpress-dot-xpo-dot-xpservercollectionsource-dot-ctor-x28-devexpress-dot-xpo-dot-session-system-dot-type-x29.md

latest5.7 KB
Original Source

XPServerCollectionSource(Session, Type) Constructor

Initializes a new instance of the XPServerCollectionSource class with a given Session and object type.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public XPServerCollectionSource(
    Session session,
    Type objectType
)
vb
Public Sub New(
    session As Session,
    objectType As Type
)

Parameters

NameTypeDescription
sessionSession

The Session that will be used to load and save persistent objects. This value is used to initialize the XPServerCollectionSource.Session property.

| | objectType | Type |

The type of an object that describes the target data table. This value is used to initialize the XPServerCollectionSource.ObjectType property, and indirectly the XPServerCollectionSource.ObjectClassInfo property.

|

Example

In the example, an XPServerCollectionSource object is created that will provide data from the “Person.Contact” table in a target database.

To link the “Person.Contact” database table with the XPServerCollectionSource object, a persistent object (Person_Contact) describing the data table is declared and its type is passed to the XPServerCollectionSource ‘s constructor. The value passed is used to initialize the XPServerCollectionSource.ObjectType property.

The Person_Contact object specifies the name of the target data table via the PersistentAttribute attribute and contains public properties corresponding to the required table’s fields.

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

public Form1() {
    // ...
    // Create a filter that selects records which contain names starting with 'A' 
    // in the LastName column
    CriteriaOperator criteria = CriteriaOperator.Parse("[LastName] LIKE ?", "A%");
    // Create a data source that provides data from the data table 
    // which is described by the Person_Contact object.
    XPServerCollectionSource serverModeDS = new XPServerCollectionSource( 
      XpoDefault.Session, typeof(Person_Contact), criteria);
}

// ...

// The persistent object that describes the "Person.Contact" table 
// in 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;

    //...
}
vb
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB
Imports DevExpress.Data.Filtering

Public Sub New()
    InitializeComponent()
    ' ...
    ' Create a filter that selects records which contain names starting with 'A' 
    ' in the LastName column
    Dim criteria As CriteriaOperator = CriteriaOperator.Parse("[LastName] LIKE ?", "A%")
    ' Create a data source that provides data from the data table 
    ' which is described by the Person_Contact object.
    Dim serverModeDS As XPServerCollectionSource = New XPServerCollectionSource( _
      XpoDefault.Session, GetType(Person_Contact), criteria)
End Sub

' The persistent object that describes the "Person.Contact" table 
' in 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

See Also

XPServerCollectionSource Class

XPServerCollectionSource Members

DevExpress.Xpo Namespace