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

Error on deleting an Entity after update to 0.9.3 #2536


User avatar
0
eggersa created

After I updated ABP from 0.8.4 to 0.9.3 I get an error when I try to delete an entity. I never run into this issue with the previous version of ABP. The error message says "The OwnerId field is required.". However, the OwnerId field is set as the following screenshot shows:

The property is defined as follows:

[Required]
        public long? OwnerId { get; set; }

        public virtual User Owner { get; set; }

Looking forward for your help.

Stack Trace

at System.Data.Entity.Internal.InternalContext.SaveChangesAsync(CancellationToken cancellationToken) at System.Data.Entity.Internal.LazyInternalContext.SaveChangesAsync(CancellationToken cancellationToken) at Abp.EntityFramework.AbpDbContext.<SaveChangesAsync>d__34.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\AbpDbContext.cs:line 201 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesInDbContextAsync>d__23.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 209 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.EntityFramework.Uow.EfUnitOfWork.<SaveChangesAsync>d__14.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 80 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.EntityFramework.Uow.EfUnitOfWork.<CompleteUowAsync>d__16.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp.EntityFramework\EntityFramework\Uow\EfUnitOfWork.cs:line 97 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Domain.Uow.UnitOfWorkBase.<CompleteAsync>d__56.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkBase.cs:line 255 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Domain.Uow.UnitOfWorkInterceptor.<>c__DisplayClass5_0.<<PerformAsyncUow>b__0>d.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Domain\Uow\UnitOfWorkInterceptor.cs:line 68 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithPostActionAndFinally>d__1.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 40 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Abp.Threading.InternalAsyncHelper.<AwaitTaskWithFinally>d__0.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Threading\InternalAsyncHelper.cs:line 20 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Threading.Tasks.TaskHelpersExtensions.<CastToObject>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__0.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Web.Http.Controllers.ExceptionFilterResult.<ExecuteAsync>d__0.MoveNext()


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

    Hi,

    If it is possible for you, can you upgrade to v1.0 ? I couldn't remember an issue related to this problem, but updating to v1.0 might fix this. If it does not, we can try to debug it by your code.

    Thanks.

  • User Avatar
    0
    eggersa created

    After a while of debugging I found the issue that was in fact already introduced with 0.9.0.0 as far as I'm concerned.

    In 0.8.4 the Delete method in the EfRepositoryBaseOfTEntityAndTPrimaryKey is implemented like this:

    public override void Delete(TEntity entity)
            {
                AttachIfNot(entity);
    
                if (entity is ISoftDelete)
                {
                    (entity as ISoftDelete).IsDeleted = true;
                }
                else
                {
                    Table.Remove(entity);
                }
            }
    

    However, in the later version the method was for some reason changed to:

    public override void Delete(TEntity entity)
            {
                AttachIfNot(entity);
                Table.Remove(entity);
            }
    

    The Remove method of Table (DbSet) internally clears all foreign keys including my Owner property (foreign key) which is marked as required. However, the SoftDelete logic later on modifies the entity and prevents its actual deletion which of course causes a validation and the results in a validation exception.

    Is there any chance to workaround this issue?

    Please do not take any offense on the following (I do a lot of erros myself and I love your framework anyway), but so far with every update was a new bug introduced that caused painful conversations with our client. Therefore I cannot afford another update.

    0.8.4 -> 0.9.0 Bug and the Delete bug 0.9.0 -> 0.9.1.1 Bug

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    No problem at all :). We are trying to make small changes between each version but sometimes it is not possible as you know in software and before 1.0 of ABP there are some changes like you mentioned. I suggest to you to follow the latest ABP version in your project if you can. I know that it might be a painfull thing to do but, you might face much more problem if you don't in the future.

    Currently, you can override the Delete method in your RepositoryBase and change it to older version if you like, what about that ?

  • User Avatar
    0
    eggersa created

    Thank you. That seems to work for me ;). We will probably update to the latest version with the next big feature request. But that really depends on our client. Lets hope is willing to pay.

  • User Avatar
    0
    ismcagdas created
    Support Team

    You are right, there is a customer reality at the end :).