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 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Swap Nodes in Pairs
    Remove Nth Node From End of List
    Rotate list
    历届试题_DNA比对
    斐波那契字符串_KMP
    字符串的模式匹配
    理解图像Garbor和HOG特征的提取方法及实例应用
    人眼定位和基于人眼的人脸姿态矫正_转载
    借助百度云API进行人脸识别
    { "result": null, "log_id": 304592860300941982, "error_msg": "image check fail", "cached": 0, "error_code": 222203, "timestamp": 1556030094 }
  • 原文地址:https://www.cnblogs.com/sunjunlin/p/1678663.html
Copyright © 2011-2022 走看看