[Summary] xpo (express persistent objects) Learning summary 2

Source: Internet
Author: User

 
6. One-to-multiple table relationships.

[Aggregated] No Parameter

Implement the cascade deletion function of two persistent classes. Simply put, if the aggregated parameter is added, the records associated with the sub-table are also deleted when the primary table is deleted, if this parameter is not added, you must delete all the data in the sub-table to delete the records in the master table.

Example:

There is a primary table v_commonreview and a subtable v_exit.
The primary key of the primary table v_commonreview is v0900.
The primary key of the child table v_exit is v0600, and the outer key is v0627.

Records in a v_commonreview table correspond to records in v_exit of multiple sub-tables.

To implement cascading, define an external region v0627 in the child table v_exit.
Type: v_commonreview object type.

<Association ("v_exitcommonreview")> Public v0627 as v_commonreview

Then define in the v_commonreview table

<Association ("v_exitcommonreview", GetType (v_exit)> _
Public readonly property v_exits () as xpcollection
Get
Return getcollection ("v_exits ")
End get
End Property

Note: v_exitcommonreview is the link name and can start with anything.

After completing this step, you can use the sub-table as a view in a database to display the records in the two tables.

For example:

(1) The following shows how to display the joined table data set.

Dim X as new xpcollection (GetType (v_exit ))
X. displayableproperties = "v0627.v0900; v0627.v0901; v0627.v0902"
Datagrid1.datasource = x
Datagrid1.databind ()

By default, if the auto-generated column attribute of the DataGrid is set to true, all contents of the sub-table are displayed, however, you can set the displayableproperties attribute of xpcollection to set the fields in the main table to be displayed.

(2) The following describes how to add and save the joined data entries.

Dim bizobject as v_exit
If checkisedit () then
Bizobject = new xpcollection (GetType (v_exit), new binaryoperator ("v0602", CINT (Session ("volunteerid"), binaryoperatortype. Equal). Object (0)

Else
Bizobject = new v_exit
End if
With bizobject
'. V0601 = ddlv0601.selectedvalue
. V0602 = CINT (Session ("volunteerid "))
. V0603 = txtv0603.text
.......

If. v0627 is nothing then '---- Here. v0627 is a Class Object
Dim Cr as new v_commonreview

With cr
. V0901 = ddlv0901.selectedvalue
. V0919 = txtv0919.text
. V_exits.add (bizobject)
. Save ()
End
Else
. V0627 = new xpcollection (GetType (v_commonreview), new binaryoperator ("v0900",. v0627.v0900, binaryoperatortype. Equal). Object (0)
. V0627.v0901 = ddlv0901.selectedvalue

. V0627.v0919 = txtv0919.text
. V0627.v _ exits. Add (bizobject)
. Save ()
End if

End


You only need to save the content of the primary table and assign values to all the sub-table fields. The sub-table content is automatically saved.

 

(3) The following shows how to display the associated table entries.

When loading data, you must first determine whether the foreign key is null, and then load the information of the main table

Dim bizobject as v_exit
If checkisedit () then
Bizobject = new xpcollection (GetType (v_exit), new binaryoperator ("v0602", CINT (Session ("volunteerid"), binaryoperatortype. Equal). Object (0)

Else
Return
End if

With bizobject
Txtv0603.text =. v0603
If not. v0627 is nothing then
Ddlv0901.selectedvalue =. v0627.v0901
Ddlv0902.selectedvalue =. v0627.v0902
End if
End

7. Obtain the object set directly by passing SQL statements!

Dim command as idbcommand
Dim reader as idatareader
Command = devexpress. xpo. session. defaultsession. connectionprovider. createcommand ()
Command. commandtext = "select * From vs_service where f0302 = 2"
Reader = command. executereader ()

Datagrid1.datasource = Reader
Datagrid1.databind ()
Reader. Close ()

8. How to delete a record

Dim bizobject as new f_familyservice
Bizobject = new xpcollection (GetType (f_familyservice), new

Binaryoperator ("f0300", editid,

Binaryoperatortype. Equal). Object (0)
Bizobject. Delete ()

Note: f0300 is the primary key of the f_familyservice table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.