V. Session:
Manage database connection information. There is a default connection: MS Access oledb provider. If you use it, you do not have to initialize the session instance in the program. But if you want to use your own connection, there are two ways: one is to change the connection information of the default connection, the other is to create your own, but you must reference it when building a persistent class. The first one is simpler. Unless the application needs to consider connecting two databases
6. Access to Binary large object fields
Use delayed loading ):
Here, you must specify a private property of the xpdelayedproperty type, and add the attribute, which is a bit tedious in design.
Public Class Customer
Inherits xpobject
'...
Private document as new xpdelayedproperty
<Delayed ("document")> _
Public property attachment () as <byte> ()
Get
Return ctype (document. Value, <byte> ())
End get
Set (byval value as <byte> ())
Document. value = Value
End set
End Property
End Class 'customer
VII. transaction support:
Transactions are indispensable in database programs.
Obviously, this function is provided by the session.
Dim account as new account
Session. defaultsession. begintransaction ()
Try
Account. Amount = Amount
Account. Save ()
Session. defaultsession. committransaction ()
Catch e as exception
Session. defaultsession. rollbacktransaction ()
Account. Reload ()
End try
Note that reload () is used when exception occurs ().
8. Check the data validity before saving:
Class account
Inherits xpobject
Public amount as double = defaultamount
Protected overrides sub beforesave ()
Mybase. beforesave ()
If not isdeleted then
If amount <0 then
Throw new exception ("negative amount ")
End if
End if
End sub 'beforesave
End Class 'account
Note that the isdeleted is determined first.
9. concurrent operations:
Provides a check mechanism to check whether the object has changed before modification. In the past, we had to write our own code to check, and now this is also available.
10. Data paging Mechanism
For large data volumes, we generally extract data in batches instead of once, reducing memory usage and accelerating extraction. Xpo provides direct support. However, it does not use xpcollection, but uses another class xpcusor. Similar to xpcollection, condition objects are also supported, but multiple pages are supported.
This design concept is puzzling. Why is it not the same?
11. Structural persistence support:
Public structure point
<Persistent ("abscissa")> Public X as integer
Public y as integer
End structure 'point
Public class shape
Inherits xpobject
Public name as string = ""
<Persistent ("location")> public position as point
End Class 'shape
Note that only the attribute structure can be persistent.