Base solution for your next web application
Open Closed

disable softdelete (soft delete) #1262


User avatar
0
patrickglaudemans created

Hi,

want to disable softdelete at update of a certain entity like:

using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
            {

                await AddReportChilds(input, report, false);
                await _reportRepository.UpdateAsync(report);
            }

It's not working.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

6 Answer(s)
  • User Avatar
    0
    hikalkan created
    Support Team

    I haven't understand why you want to disable it while updating. It's generally disabled while getting entities. Are you getting any exception or what's happening and what you expect?

    Anyway, can you try to change your code like that:

    using (UnitOfWorkManager.Current.DisableFilter(AbpDataFilters.SoftDelete))
                {
    
                    await AddReportChilds(input, report, false);
                    await _reportRepository.UpdateAsync(report);
                    await UnitOfWorkManager.Current.SaveChangesAsync();
                }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    patrickglaudemans created

    Hi, In the UOW there are some deletes of child objects from report. These deletes should be deleted, not soft deleted.

    I should I force to delete these in stead of softdelete?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    hikalkan created
    Support Team

    Hi,

    Data filters work on selecting data. If your entity is SoftDelete, ABP always soft-deletes it and prevents actually deleting.

    So, whay you can do? You can override CancelDeletionForSoftDelete method in your DbContext and prevent cancellation conditionally. Here, you can check if SoftDelete filter is enabled using this.IsFilterEnabled() extension method of EntityFramework.DynamicFilters. If it's enabled, you return from method. If not, call base method.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    patrickglaudemans created

    Hi,

    Thanks - thats what I was looking for. Obvious that datafilter are there for retrieving data.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    vladsd created

    See <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/1334">https://github.com/aspnetzero/aspnet-ze ... ssues/1334</a>

    Its a bug

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    strix20 created

    It's not a bug, it's by design, as Volosoft has clearly pointed out.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)