XAF 如何使用复合主键和复合外键

转自:http://www.cnblogs.com/Tonyyang/archive/2010/12/21/1912757.html


http://community.devexpress.com/forums/p/60725/205569.aspx

http://www1.devexpress.com/Support/Center/p/B39252.aspx

代码:

[DefaultClassOptions]
    public class Master : XPCustomObject
    {
        public Master(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here or place it only when the IsLoading property is false:
            // if (!IsLoading){
            //    It is now OK to place your initialization code here.
            // }
            // or as an alternative, move your initialization code into the AfterConstruction method.
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
        }

        private string _MasterName;
        public string MasterName
        {
            get
            {
                return _MasterName;
            }
            set
            {
                SetPropertyValue("MasterName", ref _MasterName, value);
            }
        }

        [Association("Master-Details")]
        public XPCollection<Detail> Details
        {
            get
            {
                return GetCollection<Detail>("Details");
            }
        }

        private MasterPrimaryKey _Key;
        [Key,Persistent,Browsable(false)]
        public MasterPrimaryKey Key
        {
            get
            {
                return _Key;
            }
            set
            {
                SetPropertyValue("Key", ref _Key, value);
            }
        }

        [NonPersistent]
        public string Key1
        {
            get { return Key.Key1; }
            set
            {
                _Key.Key1 = value;
            }
        }
        [NonPersistent]
        public string Key2
        {
            get { return Key.Key2; }
            set
            {
                _Key.Key2 = value;
            }
        }
        
    }

    public struct MasterPrimaryKey
    {
        [Persistent]
        public string Key1;
        [Persistent]
        public string Key2;
    }

  public class Detail : XPCustomObject
    {
        public Detail(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here or place it only when the IsLoading property is false:
            // if (!IsLoading){
            //    It is now OK to place your initialization code here.
            // }
            // or as an alternative, move your initialization code into the AfterConstruction method.
        }
        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
        }

        private int _ID;
        [Key(AutoGenerate = true)]
        public int ID
        {
            get
            {
                return _ID;
            }
            set
            {
                SetPropertyValue("ID", ref _ID, value);
            }
        }

        private string _DetailName;
        public string DetailName
        {
            get
            {
                return _DetailName;
            }
            set
            {
                SetPropertyValue("DetailName", ref _DetailName, value);
            }
        }

        private Master _Master;
        [Association("Master-Details")]
        public Master Master
        {
            get
            {
                return _Master;
            }
            set
            {
                SetPropertyValue("Master", ref _Master, value);
            }
        }
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值