How to permanently delete values from the database

孤街浪徒 提交于 2019-12-11 17:34:19

问题


I have a method that i call from a javascript, the method suppose to delete the records permanently but it does not go in to the method if the method has DataContext db = new DataContext();, it gives the error Internal Server Error

public void PermanantlyDeleteComment(GetCommentInput input)
{
    DataContext db = new DataContext();
    //Follow by the code to delete the comment
}

If i comment out DataContext db = new DataContext(); the breakpoint does go in.

I think the problem is with the datacontext but i do know know where

Here is the datacontext

public DataContext() : base("name=Default")
{
    this.Configuration.AutoDetectChangesEnabled = true;
    this.Configuration.LazyLoadingEnabled = true;
}

I'm using DataContext because abp boilerplate does not want to permanently delete, only soft delete, if you have a way that i can hard delete with boilerplate please let me know.


回答1:


Answered in this topic: https://forum.aspnetboilerplate.com/viewtopic.php?p=6180#p6193

You can override CancelDeletionForSoftDelete method in your DbContext and prevent cancellation conditionally.

So, like this:

protected override void CancelDeletionForSoftDelete(EntityEntry entry)
{
    if (IsSoftDeleteFilterEnabled)
    {
        base.CancelDeletionForSoftDelete(entry);
    }
}

Usage:

public void PermanantlyDeleteComment(GetCommentInput input)    
{
    using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.SoftDelete))
    {
        // The code to delete the comment
    }
}



回答2:


I found out that the DataContext was correct, is just i had different EntityFramework version on my Database Library (which has DataContext.cs) and my Web Library



来源:https://stackoverflow.com/questions/50173658/how-to-permanently-delete-values-from-the-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!