Base solution for your next web application
Open Closed

Saving Related data error #7089


User avatar
0
firnas created

I have added a new property to User class,

public List<ClaimedPosts> ClaimedPosts { get; set; }

Below is the class for claimed points class


public class ClaimedPosts : FullAuditedEntity<long>
    {
        public long UserId { get; set; }

        public string PostId { get; set; }

        [ForeignKey("UserId")]
        public User User { get; set; }
    }

When i try to save related data to the claimed posts it gives the below error,

Abp.Domain.Uow.AbpDbConcurrencyException
  HResult=0x80131500
  Message=Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.
  Source=Abp.EntityFrameworkCore
  StackTrace:
   at Abp.EntityFrameworkCore.AbpDbContext.<SaveChangesAsync>d__49.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Zero.EntityFrameworkCore.AbpZeroCommonDbContext`3.&lt;SaveChangesAsync&gt;d__98.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.&lt;SaveChangesInDbContextAsync&gt;d__20.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.&lt;SaveChangesAsync&gt;d__12.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.EntityFrameworkCore.Uow.EfCoreUnitOfWork.&lt;CompleteUowAsync&gt;d__14.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Domain.Uow.UnitOfWorkBase.&lt;CompleteAsync&gt;d__61.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Domain.Uow.UnitOfWorkInterceptor.&lt;&gt;c__DisplayClass6_0.&lt;&lt;PerformAsyncUow&gt;b__2>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Threading.InternalAsyncHelper.&lt;AwaitTaskWithPostActionAndFinallyAndGetResult&gt;d__5`1.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Authorization.Users.AbpUserStore`2.&lt;UpdateAsync&gt;d__36.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.AspNetCore.Identity.UserManager`1.<UpdateUserAsync>d__174.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Abp.Authorization.Users.AbpUserManager`2.&lt;UpdateAsync&gt;d__52.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at OnePoint.Points.PointsAppService.<SavePointsClaimedPosts>d__5.MoveNext() in D:\SocialRewards2\Trunk\aspnet-core\src\OnePoint.Application\Points\PointsAppService.cs:line 142

Inner Exception 1:
DbUpdateConcurrencyException: Database operation expected to affect 1 row(s) but actually affected 0 row(s). Data may have been modified or deleted since entities were loaded. See http://go.microsoft.com/fwlink/?LinkId=527962 for information on understanding and handling optimistic concurrency exceptions.

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

    Hi @firnas

    1. Could you share your ABP nuget package version ?
    2. Have you made any modification on UserAppService ?

    Thanks,

  • User Avatar
    0
    firnas created

    Hi,

    1. Where can i find the ABP nuget version?
    2. No.
  • User Avatar
    0
    maliming created
    Support Team

    Where can i find the ABP nuget version?

    Open MyCompanyName.AbpZeroTemplate.Core.csproj to view the version

    Can you share the steps to reproduce the problem?

  • User Avatar
    0
    firnas created

    I added the above claimed posts class and added it as a list property in user class. A user can have many claimed posts. I tried to add a list to the user claimed posts property and it threw the error

  • User Avatar
    0
    maliming created
    Support Team

    Can you send me the project source code (which can be a Demo project) and the steps to reproduce the problem?

    email: [email protected]

  • User Avatar
    0
    firnas created

    Sorry i cannot share the code.

    I managed to insert a record like below, but i am not sure if it is the correct approach,

    User user = await UserManager.GetUserByIdAsync(AbpSession.UserId.Value);

            List&lt;Point.ClaimedPosts&gt; claimedPosts = new List&lt;Point.ClaimedPosts&gt;();
            foreach (var post in posts)
            {
                await _claimPostRepository.InsertAsync(new Point.ClaimedPosts { UserId = user.Id, PostId = post.PostId });
            }  
    
  • User Avatar
    0
    maliming created
    Support Team

    hi @firnas Can you share the complete application service code?