Usama Shahid

Usama Shahid

  • 207
  • 9.4k
  • 894.2k

Specify On Delete No Action or On Update No Action

May 29 2018 1:18 PM
Hy Guys, I'm working on an ASP.Net Project. Actually I'm making my database with codefirst and building the relations between entities. But i'm getting an error on my last stage. My Entity code is,
  1. public class Product  
  2.     {  
  3.         public int ProductId { getset; }  
  4.   
  5.         [Required]  
  6.         [StringLength(30)]  
  7.         public string Name { getset; }  
  8.   
  9.         [Required]  
  10.         public string Description { getset; }  
  11.   
  12.         public bool Sugar { getset; }  
  13.   
  14.         public bool Featured { getset; }  
  15.   
  16.         public DateTime ArrivalTime { getset; }  
  17.   
  18.         public int FoodCategoryId { getset; }  
  19.   
  20.         public FoodCategory FoodCategory { getset; }  
  21.   
  22.         public int BrandId { getset; }  
  23.   
  24.         public Brand Brand { getset; }  
  25.   
  26.         public Guid FileDetailId { getset; }  
  27.   
  28.         [ForeignKey("FileDetailId")]  
  29.         public virtual FileDetail FileDetail { getset; }  
  30.   
  31.         public virtual ICollection Reviews { getset; }  
  32.     }  
And my File Detail Entity Class Code is,
  1.     public class FileDetail  
  2.     {  
  3.         public Guid Id { getset; }  
  4.   
  5.         [Required]  
  6.         public string FileName { getset; }  
  7.   
  8.         [Required]  
  9.         public string Extension { getset; }  
  10.     }  
And I'm getting this error. 
 
Introducing FOREIGN KEY constraint 'FK_dbo.Products_dbo.FileDetails_FileDetailId' on table 'Products' may cause cycles or multiple cascade paths. Specify ON DELETE NO ACTION or ON UPDATE NO ACTION, or modify other FOREIGN KEY constraints.
Could not create constraint or index. See previous errors.
 
Can anyone help me please?

Answers (1)