我不能先使用ef代码在同一张表上建立多对多关系。有没有人可以帮助我? 我也有一个Category类和CategoryRelation类。 Categoy类具有许多父类别和许多子类别。但是我在CategoryRelation中有一个额外的道具作为DisplayId。我的课程就像下面的
类别:
public class Category : Base
{
#region Top Menu
public int DisplayOrder { get; set; }
public bool ShowOnTopMenu { get; set; }
#endregion
public bool ShowOnTopSelling { get; set; }
[MaxLength(100)]
public string Name { get; set; }
#region Types
public bool IsPieceType { get; set; }
public bool IsGildingType { get; set; }
public bool IsPaperType { get; set; }
public bool IsSizeType { get; set; }
public bool IsWeightType { get; set; }
public bool IsCellophaneType { get; set; }
public bool IsCuttingType { get; set; }
public bool IsPrintingType { get; set; }
#endregion
public virtual ICollection<CategoryRelation> ChildCategoryList { get; set; }
public virtual ICollection<CategoryRelation> ParentCategoryList { get; set; }
public virtual ICollection<Product> ProductList { get; set; }
public virtual ICollection<WishList> WishList { get; set; }
public virtual ICollection<Description> DescriptionList { get; set; }
public virtual ICollection<Comment> CommentList { get; set; }
public virtual ICollection<Image> ImageList { get; set; }
public virtual ICollection<Template> TemplateList { get; set; }
public virtual ICollection<PromotionCode> PromotionCodeList { get; set; }
}
CategoryRelation;
public class CategoryReletion : Base
{
#region Parent Category
[ForeignKey("ParentCategory")]
public int ParentId { get; set; }
public Category ParentCategory { get; set; }
#endregion
#region Child Category
[ForeignKey("ChildCategory")]
public int ChildId { get; set; }
public Category ChildCategory { get; set; }
#endregion
public int DisplayOrder { get; set; }
}
最后我遇到这个错误;
在表“ CategoryReletion”上引入FOREIGN KEY约束“ FK_dbo.CategoryReletion_dbo.Category_ParentId”可能会导致循环或多个级联路径。指定ON DELETE NO actION或ON UPDATE NO actION,或修改其他FOREIGN KEY约束。 无法创建约束或索引。请参阅先前的错误。*