The instance of entity type 'Product' cannot be tracked because another instance with the same key value is already being tracked

后端 未结 4 607
天命终不由人
天命终不由人 2020-12-21 00:23

I made a test with code below to update the Product:

var existing = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.Id);
if (         


        
4条回答
  •  清歌不尽
    2020-12-21 00:56

    Check the value of updatedEntity.Id, if it's zero then use the below code.

    var updatedEntity = ObjectMapper.Map(input);
    updatedEntity.Id = input.Id; //set Id manually
    var entity = await _productRepository.UpdateAsync(updatedEntity);
    

提交回复
热议问题