Open Closed

Deleteasync to delete child entities #1932


User avatar
0
Neozzz created

We perform delete function on EntityName by calling the DeleteAsync on the repository EntityNameRepository.

However EntityName has a number of child tables. DeleteAsync sets the IsDeleted value to true for the EntityName however that doesn't happen for the child entities of EntityName.

How to cascade delete all entities associated with EntityName


12 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    https://github.com/abpframework/abp/issues/9366#issuecomment-869247128

  • User Avatar
    0
    Neozzz created

    Hi maliming :)

    Thanks for the reply. I was checking out the github link you shared.

    I tried to add the override for deleteasync just like how we did for the WithDetailsAsync but that didn't work out.

    Do you have any reference code which we can refer to that extends deleteasync to soft delete the subcollections ?

    Thank you

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    but that didn't work out.

    Can you explains why it doesn't work?

  • User Avatar
    0
    Neozzz created

    showing this error.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can see the DeleteAsync method in base class.

    https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs#L186 https://github.com/abpframework/abp/blob/dev/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/Domain/Repositories/EntityFrameworkCore/EfCoreRepository.cs#L439

  • User Avatar
    0
    Neozzz created

    so do we have to call deleteasync mulltiple times to delete subcollections? how do we go on and soft delete multiple subcollection. i tried x =>x.Id == id inside deleteasync but it deletes only the main record.

  • User Avatar
    0
    Neozzz created

    Hi maliming,

    awaiting your support.

    Thank you :)

  • User Avatar
    0
    Neozzz created

    Hi maliming,

    guess you're having a busy day. We all have them ;) Waiting for your reply.

    Thank you.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share your app source code again? liming.ma@volosoft.com

  • User Avatar
    0
    Neozzz created

    hey,

    i've sent you the request to the repo.

    Tx :)

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try this way.

  • User Avatar
    0
    Neozzz created

    Thanks maliming :) . I used separate repos for each of those collections as suggested and was able to set isdeleted as true.

    Thank you

Made with ❤️ on ABP v9.1.0-preview. Updated on December 05, 2024, 12:19