-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.vb
61 lines (54 loc) · 2.33 KB
/
Program.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
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports DevExpress.Xpo
Imports DevExpress.Xpo.Metadata
Imports DevExpress.Xpo.DB
Namespace CreateClassAtRuntime
Friend Class Program
Shared Sub Main(ByVal args() As String)
Dim provider As IDataStore = New DevExpress.Xpo.DB.InMemoryDataStore()
'string connectionString = MSSqlConnectionProvider.GetConnectionString("localhost", "E1139");
'IDataStore provider = XpoDefault.GetConnectionProvider(connectionString, AutoCreateOption.DatabaseAndSchema);
Dim dictionary As XPDictionary = New ReflectionDictionary()
Dim myBaseClass As XPClassInfo = dictionary.GetClassInfo(GetType(MyBaseObject))
Dim myClassA As XPClassInfo = dictionary.CreateClass(myBaseClass, "MyObjectA")
myClassA.CreateMember("ID", GetType(Integer), New KeyAttribute(True))
myClassA.CreateMember("Name", GetType(String))
XpoDefault.Session = Nothing
XpoDefault.DataLayer = New SimpleDataLayer(dictionary, provider)
'XpoDefault.DataLayer = new ThreadSafeDataLayer(dictionary, provider);
Using session As New Session()
session.UpdateSchema(myClassA)
End Using
Using session As New Session()
Console.WriteLine("Create a new object:")
Dim obj As XPBaseObject = CType(myClassA.CreateNewObject(session), XPBaseObject)
obj.SetMemberValue("Name", String.Format("sample {0}", DateTime.UtcNow.Ticks))
obj.Save()
Console.WriteLine("ID:" & vbTab & "{0}, Name:" & vbTab & "{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"))
End Using
Console.WriteLine("----------------------------")
Using session As New Session()
Dim collection As New XPCollection(session, myClassA)
Console.WriteLine("Objects loaded. Total count: {0}", collection.Count)
For Each obj As XPBaseObject In collection
Console.WriteLine("ID:" & vbTab & "{0}, Name:" & vbTab & "{1}", obj.GetMemberValue("ID"), obj.GetMemberValue("Name"))
Next obj
End Using
Console.WriteLine("----------------------------")
Console.WriteLine("Press Enter to Exit")
Console.ReadLine()
End Sub
End Class
<NonPersistent>
Public Class MyBaseObject
Inherits XPLiteObject
Public Sub New(ByVal session As Session)
MyBase.New(session)
End Sub
Public Sub New(ByVal session As Session, ByVal classInfo As XPClassInfo)
MyBase.New(session, classInfo)
End Sub
End Class
End Namespace