Exploring Cool Features of Devexpress' ASPxGridView
Listing 1: The code generated from the XPO Persistent Classes item installed when you install Devexpress controls.
Imports System Imports DevExpress.Xpo Namespace northwind Public Class Products Inherits XPLiteObject Dim fProductID As Integer <Key(true)> _ Public Property ProductID() As Integer Get Return fProductID End Get Set(ByVal value As Integer) SetPropertyValue(Of Integer)("ProductID", _ fProductID, value) End Set End Property Dim fProductName As String <Size(40)> _ Public Property ProductName() As String Get Return fProductName End Get Set(ByVal value As String) SetPropertyValue(Of String)("ProductName", fProductName, value) End Set End Property Dim fSupplierID As Integer Public Property SupplierID() As Integer Get Return fSupplierID End Get Set(ByVal value As Integer) SetPropertyValue(Of Integer)("SupplierID", fSupplierID, value) End Set End Property Dim fCategoryID As Integer Public Property CategoryID() As Integer Get Return fCategoryID End Get Set(ByVal value As Integer) SetPropertyValue(Of Integer)("CategoryID", fCategoryID, value) End Set End Property Dim fQuantityPerUnit As String <Size(20)> _ Public Property QuantityPerUnit() As String Get Return fQuantityPerUnit End Get Set(ByVal value As String) SetPropertyValue(Of String)("QuantityPerUnit", fQuantityPerUnit, value) End Set End Property Dim fUnitPrice As Decimal Public Property UnitPrice() As Decimal Get Return fUnitPrice End Get Set(ByVal value As Decimal) SetPropertyValue(Of Decimal)("UnitPrice", fUnitPrice, value) End Set End Property Dim fUnitsInStock As Short Public Property UnitsInStock() As Short Get Return fUnitsInStock End Get Set(ByVal value As Short) SetPropertyValue(Of Short)("UnitsInStock", fUnitsInStock, value) End Set End Property Dim fUnitsOnOrder As Short Public Property UnitsOnOrder() As Short Get Return fUnitsOnOrder End Get Set(ByVal value As Short) SetPropertyValue(Of Short)("UnitsOnOrder", fUnitsOnOrder, value) End Set End Property Dim fReorderLevel As Short Public Property ReorderLevel() As Short Get Return fReorderLevel End Get Set(ByVal value As Short) SetPropertyValue(Of Short)("ReorderLevel", fReorderLevel, value) End Set End Property Dim fDiscontinued As Boolean Public Property Discontinued() As Boolean Get Return fDiscontinued End Get Set(ByVal value As Boolean) SetPropertyValue(Of Boolean)("Discontinued", fDiscontinued, value) End Set End Property Public Sub New(ByVal session As Session) MyBase.New(session) End Sub Public Sub New() MyBase.New(Session.DefaultSession) End Sub Public Overrides Sub AfterConstruction() MyBase.AfterConstruction() End Sub End Class End Namespace
The generated code is straightforward. The class represents the table, and the properties represent the table columns. The setters have a call to a generic SetPropertyValue method that, if I had to guess, I would say it contains a unified dirty-state tracking mechanism. A quick scan of Reflector says it looks like SetPropertyValue checks to see whether the new value is identical to the old value and raises some events and updates the Session's version of the property state.
Page 2 of 6
This article was originally published on January 6, 2009