zoukankan      html  css  js  c++  java
  • [总结] XPO (eXpress Persistent Objects) 学习总结二

     
    6.表关系为一对多的实现方法.

    [Aggregated]   没有参数      

                  实现两个持久类的级联删除的功能,简单地说就是如果加上Aggregated参数,那么删除主表的时记录时一同连子表的记录也都删除了,如果不加那么必须把子表的数据全部删除才可以删除主表的记录.

    例子:

    有一个主表 V_CommonReview  和一个子表V_Exit
    主表V_CommonReview  主键为V0900 
    子表V_Exit  主键为V0600 外鍵为V0627

    一条V_CommonReview表中记录对应多条子表V_Exit的记录

    那么为了实现级联关系那么先在子表V_Exit定义一个外鍵为V0627
    类型为V_CommonReview对象类型.

    <Association("V_ExitCommonReview")> Public V0627 As V_CommonReview


    然后在V_CommonReview表中定义


    <Association("V_ExitCommonReview", GetType(V_Exit))> _
        Public ReadOnly Property V_exits() As XPCollection
            Get
                Return GetCollection("V_exits")
            End Get
        End Property


    注:V_ExitCommonReview为关系名称,起什么都可以


    做完这步了就可以把子表当作一个数据库中的视图显示两个表中的记录了

    例如:

    (1)  下面是实现关联表数据集合的显示功能.

     Dim x As New XPCollection(GetType(V_Exit))
            x.DisplayableProperties = "V0627.V0900;V0627.V0901;V0627.V0902"
            DataGrid1.DataSource = x
            DataGrid1.DataBind()

    默认情况下如果设置DataGrid的自动生成列属性为真,那么把子表的内容全都显示出来,但你可以通过设置XPCollection的DisplayableProperties属性来设置想要显示的主表中的字段.


    (2) 下面是实现关联表单条数据的增加和保存功能.


      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  '----这里.V0627是一个类对象
                    Dim CR As New V_CommonReview

                    With CR
                        .V0901 = ddlV0901.SelectedValue
                        .V0919 = txtV0919.Text
                        .V_exits.Add(bizObject)
                        .Save()
                    End With
                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 With

          
    只需保存主表的内容,把子表的域都赋值,那么子表的内容自动保存

    (3) 下面是实现关联表单条数据的显示功能.

    在Load数据时也要先判断一下外键是否为空,然后在Load主表信息

      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 With



    7.直接通过传SQL语句获得对象集合的方法!


      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.删除一条记录的写法

    Dim bizobject As New F_FamilyService
            bizobject = New XPCollection(GetType(F_FamilyService), New

    BinaryOperator("F0300", editID,

    BinaryOperatorType.Equal)).Object(0)
            bizobject.Delete()

    注:F0300为F_FamilyService表的主键

  • 相关阅读:
    并查集基础练习
    HDU1232——畅通工程
    二分答案——划分数列
    二分答案——收入计划
    动态规划练习题(2)
    动态规划程序设计2
    动态规划练习题(1)
    0/1背包
    P5024 保卫王国[倍增+dp]
    UVA11424 GCD
  • 原文地址:https://www.cnblogs.com/goody9807/p/270518.html
Copyright © 2011-2022 走看看