-1
  1. I dont want to update value booking.Price in database (Postgrsql) but it is getting updated.I have following code

         .........
        public async Task<AppResponse<UpdateBookingCommandResponse>> Handle(UpdateBookingCommand request, CancellationToken cancellationToken){
       var booking = await _bookingRepository.GetByGuIdAsync(request.Id);
       booking.Price = request.Price;
       var response = _mapper.Map<UpdateBookingCommandResponse>(booking);
       return Ok(response);
    }
    ...........
    
  2. Request body

        public class UpdateBookingCommand : AppRequest<UpdateBookingCommandResponse>, IAuditableRequest
     {
     .......
     public List<Product> Products { get; set; }
     public List<Location> PickupLocations { get; set; }
     public decimal OriginalPrice { get; set; }
     public decimal Price { get; set; }
     public decimal Cost { get; set; }
     .....
    }
    
  3. Response Body

    public class UpdateBookingCommandResponse
    {
      .........
     public decimal OriginalPrice { get; set; }
     public decimal Price { get; set; }
     public decimal Cost { get; set; }
     public decimal PaidAmount { get; set; }
     ......
     }
    
  4. Booking Class

    public class Booking : BaseEntity
    {
      ......
     public decimal OriginalPrice { get; set; }
     public decimal PriceCore { get; set; }
     public decimal Price { get; set; }
     public decimal PriceGst { get; set; }   
     .......
     }
    
Tika Ram
  • 1
  • 1

1 Answers1

0

If you don't want updated the value, use AsNoTracking; this function disables the modification's tracking by dbcontext and their update when you call db.saveChange() like this:

db.booking.AsNotTracking().where(b => b.id == id)

Also, next time share the function's code to get booking.

Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77
Reatir
  • 1