Back to Devexpress

XPServerCollectionSource(Session, XPClassInfo, CriteriaOperator) Constructor

xpo-devexpress-dot-xpo-dot-xpservercollectionsource-dot-ctor-x28-devexpress-dot-xpo-dot-session-devexpress-dot-xpo-dot-metadata-dot-xpclassinfo-devexpress-dot-data-dot-filtering-dot-criteriaoperator-x29.md

latest6.8 KB
Original Source

XPServerCollectionSource(Session, XPClassInfo, CriteriaOperator) Constructor

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

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
public XPServerCollectionSource(
    Session session,
    XPClassInfo objectClassInfo,
    CriteriaOperator fixedFilterCriteria
)
vb
Public Sub New(
    session As Session,
    objectClassInfo As XPClassInfo,
    fixedFilterCriteria As CriteriaOperator
)

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.

| | objectClassInfo | XPClassInfo |

An XPClassInfo object that identifies the class describing the target data table. This value is used to initialize the XPServerCollectionSource.ObjectClassInfo property, and indirectly the XPServerCollectionSource.ObjectType property.

| | fixedFilterCriteria | CriteriaOperator |

A CriteriaOperator object that specifies a filter expression applied to data on the data store side. This value is assigned to the XPServerCollectionSource.FixedFilterCriteria property.

|

Example

In the following code, an XPServerCollectionSource object is initialized with a persistent object describing a target “Person.Contact” data table (this table is included in the AdventureWorks database that ships with Microsoft SQL Server).

In the code, the Person_Contact persistent object is declared, and mapped to the “Person.Contact” data table using the PersistentAttribute attribute. It exposes specific public properties that match the data table’s fields.

To provide data on the Person_Contact object for the XPServerCollectionSource, first a corresponding XPClassInfo object is obtained. Then it’s passed to the XPServerCollectionSource’s constructor via an objectClassInfo parameter. This initializes the XPServerCollectionSource.ObjectClassInfo property.

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

public Form1() {
    // ...
    // Create an XPClassInfo object corresponding to the Person_Contact class.
    XPClassInfo classInfo = XpoDefault.Session.GetClassInfo(typeof(Person_Contact));
    // 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.
    XPServerCollectionSource serverModeDS = new XPServerCollectionSource(
      XpoDefault.Session, classInfo, 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.Metadata
Imports DevExpress.Data.Filtering

Public Sub New()
    InitializeComponent()
    ' ...
    ' Create an XPClassInfo object corresponding to the Person_Contact class.
    Dim classInfo As XPClassInfo = XpoDefault.Session.GetClassInfo(GetType(Person_Contact));
    ' 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.
    Dim serverModeDS As XPServerCollectionSource = New XPServerCollectionSource( _
      XpoDefault.Session, classInfo)
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