我正在使用Entity Framework 5,我无法连接两个每个都有复合键的表。每个表还有一对外键,一对是1:1关系(tbd_AuditHistoryID AND taw_AuditHistoryID),另一个是1:many(tbd_ParentAuditHistoryID和taw_ParentAuditHistoryID),它们都引用第三个表中的相同字段。
运行我的代码时,我收到以下错误:无法确定类型为t_TicketAsBillableAuditRegister的外键的复合外键排序。在复合外键属性上使用ForeignKey数据批注时,请确保使用Column数据批注或Fluent API指定顺序。
到目前为止,这是我的代码:
public class t_TicketAsBillableAuditRegister
{
[Key, ForeignKey("t_AuditHistory"), Column(Order = 0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.Guid tbd_AuditHistoryID { get; set; }
[Key, Column(Order = 1)]
public int Line_Number { get; set; }
[ForeignKey("t_AuditHistory"), Column(Order = 2)]
public string tbd_ParentAuditHistoryID { get; set; }
public virtual t_AuditHistory t_AuditHistory { get; set; }
}
public partial class t_TicketAsWorkedAuditRegister
{
[Key, ForeignKey("t_AuditHistory"), Column(Order = 0)]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.Guid taw_AuditHistoryID { get; set; }
[Key, Column(Order = 1)]
public int Line_Number { get; set; }
[ForeignKey("t_AuditHistory"), Column(Order = 2)]
public string taw_ParentAuditHistoryID { get; set; }
public virtual t_AuditHistory t_AuditHistory { get; set; }
}
public partial class t_AuditHistory
{
public t_AuditHistory()
{
this.t_TicketAsBillableAuditRegister = new HashSet<t_TicketAsBillableAuditRegister>();
this.t_TicketAsWorkedAuditRegister = new HashSet<t_TicketAsWorkedAuditRegister>();
}
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public System.Guid ah_ID { get; set; }
[ForeignKey("t_AuditType")]
public int ah_AuditTypeID { get; set; }
public string ah_AuditMessage { get; set; }
[ForeignKey("at_ID")]
public virtual t_AuditType t_AuditType { get; set; }
public virtual ICollection<t_TicketAsWorkedAuditRegister>
t_TicketAsWorkedAuditRegister { get; set; }
public virtual ICollection<t_TicketAsBillableAuditRegister>
t_TicketAsBillableAuditRegister { get; set; }
}
非常感谢您给予的任何帮助。