いろいろ備忘録日記

主に .NET とか Go とか Flutter とか Python絡みのメモを公開しています。

DevExpress奮闘記-007 XPOにて複合主キーを作成するには (XPO, Compound Primary Key, KeyAttribute, Multiple primary key)


以下、メモ書きです。
XPOにて、複合主キーに対応するには、以下のように構造体で複合主キーを表す
ものを作成します。


以下、サンプルです。

public struct PK{
    [Persistent("xx_id")]
    public string XXId;
    [Persistent("xx_cd")]
    public string XXCd;
}

[Persistent("TestTable"), OptimisticLocking(false)]
public class TestTable : XPBaseObject{

    [Key, Persistent]
    public PK Key;
    private string _comment;

    public TestTable() : base(Session.DefaultSession){
    }

    public TestTable(Session session) : base(session){
    }

    public string Comment{
        get{
            return _comment;
        }
        set{
            SetPropertyValue("Comment", ref _comment, value);
        }
    }

}


どうも、以下の決まりごとがあるみたいです。

  1. 親のクラスはXPBaseObjectにしなければならない。
  2. 主キー構造体の各フィールドには必ず、Persistent("xxxx")をつけなければならない。
  3. テーブルクラスの主キーフィールド宣言にも、Persistentをつけなければならない。


[参考にしたKB]


================================
過去の記事については、以下のページからご参照下さい。