I am getting this error in code first MVC CORE while inserting this and I am doing Code first for very first Time command:
Update-Database -Context ProjectDbContext
"Introducing FOREIGN KEY constraint 'FK_Product_SubCategory_SubCategoryId' on table 'Product' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints".
My Classes are are given below and also explain me why we use association in mvc model classes like this :
public virtual SubCategory SubCategory { get; set; }
Or
public virtual ICollection<Category> Category { get; set; }
public virtual Icollection<SubCategory> SubCategory { get; set; }
public class Product
{
public int ProductId { get; set; }
[Required]
public string ProductName { get; set; }
[Required]
public string ProductModel { get; set; }
[Required]
public int Quatity { get; set; }
[Required]
public int Price { get; set; }
[Required]
public string Description { get; set; }
[Required]
public string ProductColor { get; set; }
public byte Status { get; set; }
public DateTime TodayDate { get; set; }
[Required]
public int CategoryId { get; set; }
[Required]
public int SubCategoryId { get; set; }
public virtual Category Category { get; set; }
public virtual SubCategory SubCategory { get; set; }
}
public class SubCategory
{
public int SubCategoryId { get; set; }
[Required]
public string SubCategoryName { set; get; }
[Required]
public int CategoryId { get; set; }
public ICollection< Category> Category { set; get; }
public ICollection<Product> Product { set; get; }
}
public class Category
{
public int CategoryId { set; get; }
[Required]
public string Name { get; set; }
}