This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
/
XpoHelper.vb
63 lines (53 loc) · 1.47 KB
/
XpoHelper.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Imports Microsoft.VisualBasic
Imports System
Imports DevExpress.Xpo
Imports DevExpress.Xpo.DB
Imports DevExpress.Xpo.Metadata
''' <summary>
''' Summary description for XpoHelper
''' </summary>
Public NotInheritable Class XpoHelper
Private Sub New()
End Sub
Shared Sub New()
UpdateSchema()
CreateDefaultObjects()
End Sub
Public Shared Function GetNewSession() As Session
Return New Session(DataLayer)
End Function
Public Shared Function GetNewUnitOfWork() As UnitOfWork
Return New UnitOfWork(DataLayer)
End Function
Private ReadOnly Shared lockObject As Object = New Object()
Private Shared fDataLayer As IDataLayer
Private Shared ReadOnly Property DataLayer() As IDataLayer
Get
If fDataLayer Is Nothing Then
SyncLock lockObject
fDataLayer = GetDataLayer()
End SyncLock
End If
Return fDataLayer
End Get
End Property
Private Shared Function GetDataLayer() As IDataLayer
XpoDefault.Session = Nothing
Dim provider As New InMemoryDataStore()
Dim dl As IDataLayer = New SimpleDataLayer(provider)
Return dl
End Function
Private Shared Sub UpdateSchema()
GetNewSession().UpdateSchema(GetType(DataObjects.Department).Assembly)
End Sub
Private Shared Sub CreateDefaultObjects()
Using uow As UnitOfWork = GetNewUnitOfWork()
Dim dept As New DataObjects.Department(uow)
dept.Name = "Dept A"
Dim loc As New DataObjects.Location(uow)
loc.Region = "North"
loc.Departments.Add(dept)
uow.CommitChanges()
End Using
End Sub
End Class