.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+

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.v21.2.dll

Declaration

public XPServerCollectionSource(
    Session session,
    Type objectType
)

Parameters

Name Type Description
session Session

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.

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;

    //...
}
See Also