对于“代码优先”实体,我具有以下类定义:
public class Matches
{
[Key]
[Required]
[Column(Order = 1)]
public Guid MatchGroup { get; set; }
[Key]
[Required]
[Column(Order = 2)]
public long ProcedureId { get; set; }
public long MatchLevelId { get; set; }
[ForeignKey("ProcedureId")]
public virtual Procedure Procedure { get; set; }
[ForeignKey("MatchLevelId")]
public virtual ProcedureMatchLevel MatchLevel { get; set; }
}
但是在创建初始迁移时,出现以下错误:
Unable to determine composite primary key ordering for type
'Entities.Procedures' Use the ColumnAttribute or the HasKey
method to specify an order for composite primary keys.
如您所见,我正在使用[Column]
属性。
以前有人遇到过这个问题吗?我尝试使用[ForeignKey]
切换具有相同错误的[Key, ForeignKey("Procedure")]
声明的哪个属性。
程序类:
[Table("ProcedureList")]
public class Procedure
{
[Required]
public int ProcedureId { get; set; }
[Required]
public string Code { get; set; }
[Required]
public string Description { get; set; }
}