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.v24.2.dll
Declaration
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. |
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.
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;
//...
}