我有
public class FriendshipConfiguration: EntityTypeConfiguration<Friendship>
{
public FriendshipConfiguration()
{
HasKey(k => new { k.FromUserId, k.ToUserId })
.HasRequired(e => e.ApplicationUser)
.WithMany(m=> m.Friendships)
.HasForeignKey(e => new { e.FromUserId, e.ToUserId })
.WillCascadeOnDelete(false);
}
}
使用以下表格
public class Friendship
{
public ApplicationUser ApplicationUser { get; set; }
public string FromUserId { get; set; }
public string ToUserId { get; set; }
public FriendshipStatus FriendshipStatusId { get; set; }
public DateTime RequestedDateTime { get; set; }
public DateTime? ResponseDateTimeTime { get; set; }
}
和
public class ApplicationUser
{
...
public ICollection<Friendship> Friendships { get; set; }
}
我希望最终拥有(FromUserId,ToUserId)主复合键以及ApplicationUser的外键。
我遇到以下错误
Friendship_ApplicationUser_Target_Friendship_ApplicationUser_Source ::关系约束中的从属角色和主要角色中的属性数必须相同。