2
public class Category
{
[Key]
public int CategoryId { get; set; }
public int ParentCategoryId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public int Status { get; set; }
public virtual ICollection<Category> ParentCategories { get; set; }
public virtual ICollection<ImageSet> ImageSets { get; set; }
[ForeignKey("ParentCategoryId")]
public virtual Category ParentCategory { get; set; }
}
public class ImageSet
{
[Key]
public int ImageSetId { get; set; }
public int CategoryId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string InsertDate { get; set; }
public int Status { get; set; }
public virtual ICollection<Image> Images { get; set; }
[ForeignKey("CategoryId")]
public virtual Category Category { get; set; }
}
public class Image
{
[Key]
public int ImageId { get; set; }
public int ImageSetId { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string ImageUrl { get; set; }
public string ThumbImageUrl { get; set; }
public string InsertDate { get; set; }
public int Status { get; set; }
[ForeignKey("ImageSetId")]
public virtual ImageSet ImageSet { get; set; }
}
Context:
public DbSet<Category> Categories { get; set; }
public DbSet<Image> Images { get; set; }
public DbSet<ImageSet> ImageSets { get; set; }
錯誤頁:在表將外鍵約束「FK_dbo.ImageSets_dbo.Categories_CategoryId」「ImageSets」可以 原因循環或多個級聯路徑。指定ON DELETE NO ACTION或 ON UPDATE NO ACTION,或修改其他FOREIGN KEY約束。 可能不會創建約束。查看以前的錯誤。代碼優先一對多的關係和類別與父類別
最新問題?
由於其工作。 –
很高興幫助兄弟;)@RamazanSağır – renakre
Eyvallah hocam,安拉razıolsun ...Şumecraya daTürkçeserpiştirelimbiraz。 :d –