Back to Devexpress

XPServerCollectionSource.ObjectClassInfo Property

xpo-devexpress-dot-xpo-dot-xpservercollectionsource-4470b527.md

latest8.0 KB
Original Source

XPServerCollectionSource.ObjectClassInfo Property

Gets a XPClassInfo object that describes the target data table in the data store.

Namespace : DevExpress.Xpo

Assembly : DevExpress.Xpo.v25.2.dll

NuGet Package : DevExpress.Xpo

Declaration

csharp
[DefaultValue(null)]
public XPClassInfo ObjectClassInfo { get; set; }
vb
<DefaultValue(Nothing)>
Public Property ObjectClassInfo As XPClassInfo

Property Value

TypeDefaultDescription
XPClassInfonull

An XPClassInfo object that describes the target data table in the data store.

|

Remarks

The XPServerCollectionSource.ObjectType and XPServerCollectionSource.ObjectClassInfo properties provide information that describes the target data table. These properties are synchronized. When initializing the XPServerCollectionSource.ObjectType property, the XPServerCollectionSource.ObjectClassInfo property is initialized with a matching object, and vice versa.

Do not change the XPServerCollectionSource.ObjectType and XPServerCollectionSource.ObjectClassInfo properties directly in your code. Instead, initialize these properties via the objectClassInfo or objectType parameter of the XPServerCollectionSource‘s constructor.

See the XPServerCollectionSource topic, for information on how to provide descriptive information on the target data table.

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

Example

The following code shows how to initialize an XPServerCollectionSource object with a typed DataTable object.

It’s assumed that a project contains a DataSet class (AdventureWorksDataSet) which owns the target DataTable (_Person_ContactDataTable). In the code, first a XPClassInfo object corresponding to the data table is created. Then it’s passed to the XPServerCollectionSource object’s constructor via the objectClassInfo parameter, initializing the XPServerCollectionSource.ObjectClassInfo property.

csharp
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;

// Create an XPClassInfo object corresponding to the _Person_ContactDataTable data table.
XPClassInfo classInfo = XpoDefault.Session.GetClassInfo(
  typeof(AdventureWorksDataSet._Person_ContactDataTable));
// Create a data source.
XPServerCollectionSource serverModeDS = new XPServerCollectionSource(
  XpoDefault.Session, classInfo);
vb
Imports DevExpress.Xpo
Imports DevExpress.Xpo.Metadata

' Create an XPClassInfo object corresponding to the _Person_ContactDataTable data table.
Dim classInfo As XPClassInfo = XpoDefault.Session.GetClassInfo( _
  GetType(AdventureWorksDataSet._Person_ContactDataTable))
' Create a data source.
Dim serverModeDS As XPServerCollectionSource = New XPServerCollectionSource( _
  XpoDefault.Session, classInfo)

See Also

XPServerCollectionSource Class

XPServerCollectionSource Members

DevExpress.Xpo Namespace