Multiple foreign keys to the same table

后端 未结 4 427
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 16:54

I have a reference table with all sorts of controlled value lookup data for gender, address type, contact type, etc. Many tables have multiple foreign keys to this reference tab

4条回答
  •  情书的邮戳
    2021-02-04 17:51

    So I went down the partial classes route. For instance, I added the following member to address the first reference member in my original example:

    public partial class tb_account
    {
        public tb_reference shipping_preference_reference
        {
            get
            {
                return this._tb_reference.Entity;
            }
            set
            {
                this.tb_reference = value;
            }
        }
    

    This is far from perfect. It requires a substantial amount of extra code in a large model, and depends on the order of the attributes to not change (if another foreign key to the reference table is added to the account table, this member may actually point to something else than the shipping preference). There is an upside, too. Since I am already writing partial classes for other purposes, adding these members did not require that I rearchitect the application.

提交回复
热议问题