zoukankan      html  css  js  c++  java
  • XPO 第三方控件学习(DevExpress Persistent Object )系列表间关系

         支持一对一,一对多,多对多三种关系。

    数据库的表间关系在框架内体现为持久对象之间的关系。一般我们在设计一些类似关系的类时,我们用数组或者其他集合表示方法IList等等,来为类之间建立关系。

    XPO使用XPCollection来表示类之间的”对多关系”。并且附加属性来表示多对多还是一对多的关系。

    1、一对多:

    在一个类中定义:

    Public Class Customer

        Inherits XPObject

        <Association("CustomerAddresses", GetType(Address))> _

        Public ReadOnly Property Addresses() As XPCollection

            Get

                Return GetCollection("Addresses")

            End Get

        End Property

    End Class 'Customer

    同时另一个类Adresses中定义:

        <Association("CustomerAddresses")> Public Customer As Customer

    此时这个类的关联关系并没有指定关联类型,因为已经说明了类型。

    可以在关联关系中进一步指定其他附加属性,比如级联删除关系:

    Public Class Customer

        Inherits XPObject

        <Association("CustomerOrders", GetType(Order)), Aggregated()> _

           Public ReadOnly Property Orders() As XPCollection

            Get

                Return GetCollection("Orders")

            End Get

        End Property

    End Class 'Customer 

    多了Aggregated这种特性,表示聚集,也就是表之间的级联删除关系。

    访问子表的方法:枚举

    Dim theOrder As Order

    For Each theOrder In  theCustomer.Orders '

    '…

    Next theOrder           

    增加子表的记录:

    myCustomer.Orders.Add(myOrder)

    作者:johnny 出处:http://www.cnblogs.com/sunjunlin 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    robotframework用例报错后不中断继续执行
    robotframework Excel Library关键字
    robotframework操作excel
    如何快速解决 raise ReadTimeoutError(self._pool, None, 'Read timed out.')方案robotframework
    JavaScript快速排序
    pytorch 中的 split
    Pytorch的Reproducibility(可复现性)
    卷积神经网络训练经验
    Tensor RT使用记录
    (开会2019/3/16)
  • 原文地址:https://www.cnblogs.com/sunjunlin/p/1678663.html
Copyright © 2011-2022 走看看