Open Closed

ABP EF Core delete problem with ISoftDelete in related child entities #5828


User avatar
0
ElifKaya created

Hi,

When we use child entity with ISoftDelete, we got an exception on deletion function of repository. But, when we remove implementation of ISoftDelete interface, then we completed deletion successfully. Could you solve about this problem? Because, we have previously opened different questions on this problem. I'am sharing with our question link at the bottom.

https://support.abp.io/QA/Questions/2576/Ef-Core-Abp-Extension-can-not-delete-children-entities-without-deleting-parent-entity

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, and please first use the search on the homepage. Provide us with the following info:

.* ABP Framework version: v7.3.1

  • UI Type: / MVC /
  • Database System: EF Core SQL Server,
  • Tiered (for MVC) or Auth Server Separated (for Angular): yes
  • Exception message and full stack trace:
  • Steps to reproduce the issue:.

3 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi ElifKaya,

    Can you please confirm whether you are implementing ISoftDelete for your parent entity also, in your case for Model entity ?

    Thank you, Anjali

  • User Avatar
    0
    ElifKaya created

    Can you please confirm whether you are implementing ISoftDelete for your parent entity also, in your case for Model entity ?

    Thank

    Hi,

    Actually, I added ISoftDelete interface in only child entities. Do we have to use it in both parent and child tables? We used only hard deletion in a parent entity.

    Now I added it to the parent entity as well and it worked.

    Thanks

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hi ElifKaya,

    As you are trying to hard delete the parent it is throwing error, since the child entities have the parent entity reference (ModelId). By implementing ISoftDelete it is setting IsDeleted to "true", so the reference will exist. So either you can set soft delete for both parent and child entities, or set hard deletion for both.

    Also you can try cascade try: .OnDelete(DeleteBehavior.Cascade)

    FYI: https://docs.abp.io/api-docs/abp/3.1/api/Volo.Abp.ISoftDelete.html Also please refer previous ticket related to this : https://support.aspnetzero.com/QA/Questions/493/Delete-Parent-Child-Data-in-ABP https://support.abp.io/QA/Questions/1136/Is-there-a-good-way-to-delete-related-records

    please do let me know if this helps you

    Thank you, Anjali

Made with ❤️ on ABP v9.1.0-preview. Updated on November 01, 2024, 05:35