简体   繁体   中英

I don't want to update the value in into database but its getting updated in dot NETCore

  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; }....... }

If you don't want updated the value use AsNoTracking, this function disable 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM