我有一个带有复合键和复合外键的模型。是否可以将常量而不是列名传递给外键注释?
当前型号:
[Table("PBDS.INTERACTIONS")]
public partial class Interaction
{
// NOTE: The primary key for the INTERACTIONS table is a composite key
// consisting of:
// - ACCOUNT_ID
// - CONTACT_DATE
// - CONTACT_SEQ
// - PAGE
[Key]
[Column("ACCOUNT_ID", Order = 0)]
public int ACCOUNT_ID { get; set; }
[Key]
[Column("CONTACT_DATE", Order = 1)]
public DateTime CONTACT_DATE { get; set; }
[Key]
[Column("CONTACT_SEQ", Order = 2)]
public int CONTACT_SEQ { get; set; }
[Key]
[Column("PAGE", Order = 3)]
public int PAGE { get; set; }
[ForeignKey("ACCOUNT_ID,CONTACT_DATE,CONTACT_SEQ,PAGE,DATA_VALUE")]
public InteractionData InteractionData { get; set; }
}
DATA_VALUE在我看来将始终是一个常量。理想情况下,我希望我可以进行这样的外键设置:
所需模型:
[Table("PBDS.INTERACTIONS")]
public partial class Interaction
{
// NOTE: The primary key for the INTERACTIONS table is a composite key
// consisting of:
// - ACCOUNT_ID
// - CONTACT_DATE
// - CONTACT_SEQ
// - PAGE
[Key]
[Column("ACCOUNT_ID", Order = 0)]
public int ACCOUNT_ID { get; set; }
[Key]
[Column("CONTACT_DATE", Order = 1)]
public DateTime CONTACT_DATE { get; set; }
[Key]
[Column("CONTACT_SEQ", Order = 2)]
public int CONTACT_SEQ { get; set; }
[Key]
[Column("PAGE", Order = 3)]
public int PAGE { get; set; }
[ForeignKey("ACCOUNT_ID,CONTACT_DATE,CONTACT_SEQ,PAGE,<Net_Cost_Constant_String>")]
public InteractionData NetCost { get; set; }
[ForeignKey("ACCOUNT_ID,CONTACT_DATE,CONTACT_SEQ,PAGE,<Airing_Phone_Constant_String>")]
public InteractionData AiringPhone { get; set; }
[ForeignKey("ACCOUNT_ID,CONTACT_DATE,CONTACT_SEQ,PAGE,<RepFirm_Constant_String>")]
public InteractionData RepFirm { get; set; }
[ForeignKey("ACCOUNT_ID,CONTACT_DATE,CONTACT_SEQ,PAGE,<Week_Day_Constant_String>")]
public InteractionData WeekDay { get; set; }
}
请注意, DATA_VALUE 中有130个唯一值,但我只想在此处列出4个。
这可能吗?也欢迎使用其他方法。