سلام
من ارتباط بین دو مدلم به این صورت هست
ApplicationUser.cs
[InverseProperty("ApplicationUser_Sender")] public virtual List<ReferralTicket> SenderRelations { get; set; } [InverseProperty("ApplicationUser_Rec1")] public virtual List<ReferralTicket> Rec1Relations { get; set; } [InverseProperty("ApplicationUser_Rec2")] public virtual List<ReferralTicket> Rec2Relations { get; set; }
RefreralTicket.cs
[Key] public int ReferralTicket_Id { get; set; } [ForeignKey("Sen_Id")] public ApplicationUser ApplicationUser_Sender { get; set; } public string Sen_Id { get; set; } [ForeignKey("Rec1_Id")] public ApplicationUser ApplicationUser_Rec1 { get; set; } public string Rec1_Id { get; set; } [ForeignKey("Rec2_Id")] public ApplicationUser ApplicationUser_Rec2 { get; set; } public string Rec2_Id { get; set; }
ولی هنگام حذف نمودن یه کاربر از Application User این اررو رو میده چه طور بنویسم که Cascade باشه یعنی تا کاربر اصلی رو پاک کردم اطلاعات مربوط به اون در جدول Referal Ticket هم پاک بشه
Error
SqlException: The DELETE statement conflicted with the REFERENCE constraint "FK_ReferralTickets_AspNetUsers_Sen_Id". The conflict occurred in database "Project_Management_Database", table "dbo.ReferralTickets", column 'Sen_Id'.
The statement has been terminated.
لینک زیر را بررسی کنید.
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)