Business Class can be implemented in your application either from scratch by inherit your class from BaseObject or by using Business Class Library, which is contains the most common business classes such as Contact class which is include basic information about contact like FullName, SpouseName, FirstName and LastName. Note that only public members are mapped into database tables.
Create Business Class by inheriting from BaseObject:
Create Business Class by using Business Class Library:
Create Business Class by inheriting from BaseObject:
1: Imports System
2: Imports System.ComponentModel
3:
4: Imports DevExpress.Xpo
5: Imports DevExpress.Data.Filtering
6:
7: Imports DevExpress.ExpressApp
8: Imports DevExpress.Persistent.Base
9: Imports DevExpress.Persistent.BaseImpl
10: Imports DevExpress.Persistent.Validation
11:
12:
13: <DefaultClassOptions()> _
14: Public Class Department
15: Inherits BaseObject
16: <Association("DepartmentContacts", GetType(Contact))> Public ReadOnly Property
Contacts As XPCollection
17: Get
18: Return GetCollection("Contacts")
19: End Get
20: End Property
21: Private _departmentName As String
22: Public Property DepartmentName As String
23: Set(ByVal value As String)
24: SetPropertyValue("DepartmentName", Me._departmentName, value)
25: End Set
26: Get
27: Return Me._departmentName
28: End Get
29: End Property
30: Public Sub New(ByVal session As Session)
31: MyBase.New(session)
32: ' This constructor is used when an object is loaded from a persistent storage.
33: ' Do not place any code here or place it only when the IsLoading property is false:
34: ' if (!IsLoading){
35: ' It is now OK to place your initialization code here.
36: ' }
37: ' or as an alternative, move your initialization code into the AfterConstruction method.
38: End Sub
39: Public Overrides Sub AfterConstruction()
40: MyBase.AfterConstruction()
41: ' Place here your initialization code.
42: End Sub
43: End Class
Create Business Class by using Business Class Library:
1: Imports System
2: Imports System.ComponentModel
3:
4: Imports DevExpress.Xpo
5: Imports DevExpress.Data.Filtering
6:
7: Imports DevExpress.ExpressApp
8: Imports DevExpress.Persistent.Base
9: Imports DevExpress.Persistent.BaseImpl
10: Imports DevExpress.Persistent.Validation
11:
12:
13: <DefaultClassOptions()> _
14: Public Class Contact
15: Inherits Person
16: Private _department As Department
17: Private lfname As String
18: Private llname As String
19: Private _webPageAddress As String
20: Private _nickName As String
21: Private _spouseName As String
22: Private _manager As Contact
23: Private _titleOfCourtesy As TitleOfCourtesy
24: Private _notes As String
25: Private _anniversary As String
26: Private _changeHistory As XPCollection(Of AuditDataItemPersistent)
27:
28: Public Sub New(ByVal session As Session)
29: MyBase.New(session)
30: ' This constructor is used when an object is loaded from a persistent storage.
31: ' Do not place any code here or place it only when the IsLoading property is false:
32: ' if (!IsLoading){
33: ' It is now OK to place your initialization code here.
34: ' }
35: ' or as an alternative, move your initialization code into the AfterConstruction method.
36: End Sub
37: Public ReadOnly Property AuditTrail As XPCollection(Of AuditDataItemPersistent)
38: Get
39: If Me._changeHistory Is Nothing Then
40: Me._changeHistory = AuditedObjectWeakReference.GetAuditTrail(Session, Me)
41: End If
42: Return Me._changeHistory
43: End Get
44: End Property
45: <DataSourceProperty("Department.Contacts")> _
46: Public Property Manager As Contact
47: Set(ByVal value As Contact)
48: SetPropertyValue("Manager", Me._manager, value)
49: End Set
50: Get
51: Return Me._manager
52: End Get
53: End Property
54: <Association("DepartmentContacts", GetType(Department))>
55: Public Property Department() As Department
56: Set(ByVal value As Department)
57: SetPropertyValue("Department", Me._department, value)
58: End Set
59: Get
60: Return Me._department
61: End Get
62: End Property
63: <Association("ContactsDemoTasks", GetType(DemoTask))> Public ReadOnly Property
DemoTasks() As XPCollection
64: Get
65: Return GetCollection("DemoTasks")
66: End Get
67: End Property
68: Public Property Anniversary As String
69: Set(ByVal value As String)
70: SetPropertyValue("Anniversary", Me._anniversary, value)
71: End Set
72: Get
73: Return Me._anniversary
74: End Get
75: End Property
76: Public Property Notes As String
77: Set(ByVal value As String)
78: SetPropertyValue("Notes", Me._notes, value)
79: End Set
80: Get
81: Return Me._notes
82: End Get
83: End Property
84: Public Property TitleOfCourtesy As TitleOfCourtesy
85: Set(ByVal value As TitleOfCourtesy)
86: SetPropertyValue("TitleOfCourtsy", Me._titleOfCourtesy, value)
87: End Set
88: Get
89: Return Me._titleOfCourtesy
90: End Get
91: End Property
92: Public Property SpouseName As String
93: Get
94: Return Me._spouseName
95: End Get
96: Set(ByVal value As String)
97: SetPropertyValue("SpouseName", Me._spouseName, value)
98: End Set
99: End Property
100: Public Property NickName As String
101: Set(ByVal value As String)
102: SetPropertyValue("NickName", Me._nickName, value)
103: End Set
104: Get
105: Return Me._nickName
106: End Get
107: End Property
108: Public Property WebPageAddress As String
109: Get
110: Return Me._webPageAddress
111: End Get
112: Set(ByVal value As String)
113: SetPropertyValue("WebPageAddress", Me._webPageAddress, value)
114: End Set
115: End Property
116: Public Property FirstName() As String
117: Set(ByVal value As String)
118: SetPropertyValue("FirstName", Me.lfname, value)
119: End Set
120: Get
121: Return Me.lfname
122: End Get
123:
124: End Property
125: Public Property LastName() As String
126: Set(ByVal value As String)
127: SetPropertyValue("LastName", Me.llname, value)
128: End Set
129: Get
130: Return Me.llname
131: End Get
132: End Property
133:
134: Public Overrides Sub AfterConstruction()
135: MyBase.AfterConstruction()
136: ' Place here your initialization code.
137: End Sub
138: End Class
139:
140: Public Enum TitleOfCourtesy
141: Dr
142: Miss
143: Mr
144: Mrs
145: Ms
146: End Enum
No comments:
Post a Comment