Base solution for your next web application
Open Closed

Issue With AspNetZero/ABP Entityframework And Repositories For Data Update Type A Message #9639

razkhan78 created

Hi, We have AspNetZero (Paid) Product version --> 4.0 Product type --> MVC Product framework type --> .net core

and we are having following issue right now:

We have 3 tables Table Product Table ProductPayment & ProductPaymentDetail

We have an operation where we delete data from ProductPayment (which deletes automatically any child data from ProductPaymentDetail) and updating boolean column IsPaid in Product.

We are facing an issue that "sometimes" in Product table IsPaid is not getting updated. When we check Audit Logs , we see update operation in AbpEntityChanges for product but no field change in AbpEntityPropertyChanges and Product table itself.

public async Task Delete(EntityDto input)

            var productPayment = await _productPaymentRepository.FirstOrDefaultAsync(m => m.Id == input.Id);
            var productPaymentDetail  = _ProductPaymentDetailRepository.GetAll().Where(x => x.ProductPaymentId == (int)input.Id && x.ProductId != null).GroupBy(x => x.ProductId);            

            if (productPaymentDetail != null)
                foreach (var item in productPaymentDetail)
                    var product = await _productRepository.FirstOrDefaultAsync(item.Key.Value);
                    product.IsPaid  = false;
                    await _productRepository.UpdateAsync(product);

            await _productPaymentRepository.DeleteAsync(input.Id);

1 Answer(s)
  • 0
    gterdem created
    Support Team

    Hello @razkhan78,

    For a starter, i would change the line var product = await _productRepository.FirstOrDefaultAsync(item.Key.Value); to var product = await _productRepository.FirstAsync(item.Key.Value); to ensure the product is not null by monitoring the logs.

    Also in this line: var productPaymentDetail = _ProductPaymentDetailRepository.GetAll().Where(x => x.ProductPaymentId == (int)input.Id && x.ProductId != null).GroupBy(x => x.ProductId); You're probably casting string input to int which may cause unexpected results causing productPaymentDetail to null hence skipping updating the product.