Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Disable isdeleted #1728


User avatar
0
fahad created

Hello, I want to delete record permanent. So, I do not want to use ( IsDelete ) column in all my application. How ?

Thanks,


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Please see this forup topic #1262@bdddb0a5-7f84-448e-a584-a913d1424ad1

    You can override CancelDeletionForSoftDelete method in your DbContext as halil offered.

  • User Avatar
    0
    fahad created

    Hi, I could not understand the link you sent. I Do not want to use this field ( isdeleted ) in whole my application for all tables. I want to use hard delete NOT Soft delete.

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Most of the entities come from Abp.Zero package implements ISoftDelete. When an entity implements ISoftDelete ABP does not delete it from database by default. You can see it here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/d4c7fe14b8905efa9f9846f338c659a970e157e9/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L428">https://github.com/aspnetboilerplate/as ... xt.cs#L428</a>.

    So, in order to do what you are asking you have two options. 1 ) Delete implementation of ISoftDelete in Abp.Zero entities. But you cannot do it because you have a dll reference to it. You can create a local copy of it and change the code but I dont suggest that. You cannot update ABP in the future.

    1. override the method CancelDeletionForSoftDelete in your DbContext and remove it's code.
    protected override void CancelDeletionForSoftDelete(DbEntityEntry entry)
    {
    
    }
    

    In this way, all entities will be deleted from database. But you will have IsDeleted column in some entities. In order to delete IsDeleted columns, you can override IsDeleted field in the entities you want like this.

    [NotMapped]
    public override bool IsDeleted { get; set; }
    

    Then generate code first migration and update your database. But dont forget, you still have to override CancelDeletionForSoftDelete in this case because ABP does not check IsDeleted column it checks if entity implements ISoftDelete here <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/blob/d4c7fe14b8905efa9f9846f338c659a970e157e9/src/Abp.EntityFramework/EntityFramework/AbpDbContext.cs#L428">https://github.com/aspnetboilerplate/as ... xt.cs#L428</a>

  • User Avatar
    0
    fahad created

    Thanks for your reply. I have sample project ( Acme.PhoneBook) for entity ( Phone ) there is no ( Isdeleted column ) and not used the way as you reply >[NotMapped]

    public override bool IsDeleted { get; set; }

    Kindly explain me How ?

    Regards,

  • User Avatar
    0
    fahad created

    [quote="ismcagdas"]Hi,

    1. override the method CancelDeletionForSoftDelete in your DbContext and remove it's code.
    protected override void CancelDeletionForSoftDelete(DbEntityEntry entry)
    {
    
    }
    

    What is the file to write this code ?

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Because the Phone entity does not implement ISoftDelete interface. Because of that there is no IsDeleted column. If you delete a Phone entity, it will be deleted from database as well. See <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-samples/blob/master/PhoneBook/src/Acme.PhoneBook.Core/Phones/Phone.cs">https://github.com/aspnetzero/aspnet-ze ... s/Phone.cs</a>

    For the second question, you need to override it in your DbContext class. Its name starts with your project name. [YourProjectName]DbContext. You can find it in your EntityFramework project.

  • User Avatar
    0
    fahad created

    There are (CreationDate & CreationUserID ) only , I want also ( ModifiedData, ModifiedUserID)

    Thanks,

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Then you can derive your entity from AuditedEntity<long> instead of CreationAuditedEntity<long>.

  • User Avatar
    0
    fahad created

    Thanks,