我收到一个关于两个实体约束的错误,我对此感到头疼。我用谷歌搜索并仔细检查并尝试了建议,但仍然没有运气。我得到的错误如下: -
引入FOREIGN KEY约束 桌上的'FK_dbo.UserTrackableItems_dbo.Users_ModifiedById' 'UserTrackableItems'可能会导致循环或多个级联路径。 指定ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他 FOREIGN KEY约束。无法创建约束或索引。看到 以前的错误。
我理解错误,但没有看到修复它的位置。我删除了[必需],我尝试使用流畅的API,我一定做错了。这些是它提到的实体(其中一个是基类)。
[Table("UserTrackableItems")]
public class UserTrackableItem : BaseEntity
{
[Key]
public long UserTrackableItemId { get; set; }
[Required]
public long UserId { get; set; }
[ForeignKey("UserId")]
public virtual User User { get; set; }
[Required]
public int TrackableItemId { get; set; }
[ForeignKey("TrackableItemId")]
public virtual TrackableItem TrackableItem { get; set; }
[Required]
public int OrderBy { get; set; }
}
[Table("Users")]
public class User : BaseEntity
{
[Key]
public long UserId { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string Email { get; set; }
public string Password { get; set; }
public string Hash { get; set; }
public string AvatarImage { get; set; }
public DateTime? DateOfBirth { get; set; }
public int? CountryId { get; set; }
public DateTime MemberSince { get; set; }
public bool IsAdmin { get; set; }
public bool IsWriter { get; set; }
public bool IsStaff { get; set; }
public bool IsBanned { get; set; }
public string OpenId { get; set; }
public string OpenIdClaim { get; set; }
public ExternalAuthOrigin ExternalAuthOrigin { get; set; }
public virtual ICollection<DailyTarget> DailyTargets { get; set; }
public virtual ICollection<SectionTarget> MealTargets { get; set; }
public virtual ICollection<Section> Meals { get; set; }
public virtual ICollection<UserTrackableItem> TrackableItems { get; set; }
}
public class BaseEntity
{
public DateTime AddedDate { get; set; }
public long AddedById { get; set; }
[ForeignKey("AddedById")]
public virtual User AddedBy { get; set; }
public DateTime? DeletedDate { get; set; }
public long? DeletedById { get; set; }
[ForeignKey("DeletedById")]
public virtual User DeletedBy { get; set; }
public DateTime ModifiedDate { get; set; }
public long ModifiedById { get; set; }
[ForeignKey("ModifiedById")]
public virtual User ModifiedBy { get; set; }
}
[Table("TrackableItems")]
public class TrackableItem
{
[Key]
public int TrackableItemId { get; set; }
[Required]
public string Name { get; set; }
public string MeasurementName { get; set; }
public virtual ICollection<UserTrackableItem> Users { get; set; }
}