[总结] XPO (eXpress Persistent Objects) 学习总结一
小弟水平不高,有什么地方不妥或不对的地方请指正,谢谢!
1.绑定一般的DropDownList
M_ReferringAgentAndGP是一个对应数据库表的实体类,
M0201是要显示的文本,M0200要显示的文本对应的值域
Dim Agent As XPCollection = New XPCollection(GetType(M_ReferringAgentAndGP))
ddlF1609.DataSource = Agent
ddlF1609.DataTextField = "M0201"
ddlF1609.DataValueField = "M0200"
ddlF1609.DataBind()
2.绑定有组合字段的DropDownList
M_StaffDetails类中有M0000,M0002,M0003字段域,分别对应主鍵,FirstName,LastName
Dim sName As XPCollection = New XPCollection(GetType(M_StaffDetails))
ddlF1617.DataSource = sName
ddlF1617.DataTextField = "FullName"
ddlF1617.DataValueField = "M0000"
ddlF1617.DataBind()
在M_StaffDetails类中加入如下属性:
<Persistent()> _
Public ReadOnly Property FullName() As String
Get
Return String.Format("{0} {1}", M0002, M0003)
End Get
End Property
在生成数据库时会把FullName当作一个字段创建出来
3.通过主鍵获得唯一一条记录
F_DomesticViolence是对应数据库中的一个表的类,ID是这个表的主鍵
Dim bizObject As New F_DomesticViolence
Dim newSession As New DevExpress.Xpo.Session
newSession.ConnectionString = DevExpress.Xpo.Session.DefaultSession.ConnectionString
bizObject = newSession.GetObjectByKey(GetType(F_DomesticViolence), CStr(ID))
4.新增和保存一条记录
加重显示的地方是关键,开始没这样写,导致每次操作都是新增数据,后来想到由于是持久性对象,所以
只要不释放,它一直都存在,如果每次都 Dim bizObject As New ... ,那么每点保存按钮时,重新建立一个对象
所以导致每次都是新增数据,要想保存必须找到以前的持久性对象,所以用了如下方法!
Dim bizObject As New F_DomesticViolence
If Request.QueryString("mode") = "edit" Then
bizObject = New XPCollection(GetType(F_DomesticViolence), New BinaryOperator("F1600", editID, BinaryOperatorType.Equal)).Object(0)
End If
With bizObject
.F1601 = chkF1601.Checked
.F1602 = chkF1602.Checked
.F1603 = chkF1603.Checked
.F1604 = chkF1604.Checked
.F1605 = ddlF1605.SelectedValue
.F1606 = chkF1606.Checked
.F1607 = chkF1607.Checked
.F1608 = chkF1608.Checked
.F1609 = ddlF1609.SelectedValue
.F1610 = txtF1610.Text
.F1611 = txtF1611.Text
.F1613 = chkF1613.Checked
.F1614 = chkF1614.Checked
.F1615 = chkF1615.Checked
.F1616 = txtF1616.Text
.F1617 = ddlF1617.SelectedValue
.F1618 = saveDateNull(txtF1618)
.F1619 = txtF1619.Text
'If Request.QueryString("mode") = "edit" Then
'.F1600 = 9
'End If
.Save()
End With
5.多条件查询,返回对象集合!
加重显示的语句可以增加多个条件
Dim cond As New GroupOperator
Dim oper1 As New BinaryOperator(New OperandProperty("F1400"), New OperandValue(2), BinaryOperatorType.Greater)
Dim oper2 As New BinaryOperator(New OperandProperty("F1401"), New OperandValue(1), BinaryOperatorType.Equal)
cond = New GroupOperator(GroupOperatorType.And, oper1, oper2)
Dim Collection1 As New XPCollection(GetType(F_ExitInterview), cond)
DataGrid1.DataSource = Collection1
DataGrid1.DataBind()
并且想请教一个问题,如何用XPO生成视图!请高手赐教!