The problem is you are loading the entity with the specified ID, then creating a new instance of the class with the same ID, and attaching that new instance to the context.
Instead, you should be updating the existing entity instance:
Patient patient = t_Context.Patients.FirstOrDefault(p => p.idPatient == t_Entity.idPatient);
if (patient == null)
{
patient = new Patient();
t_Context.Patients.Add(patient);
}
iMapper.Map(t_Entity, patient);
t_Context.SaveChanges();
NB: For performance reasons, you should be configuring your mappings
once, when your application starts up.
Getting Started Guide — AutoMapper documentation[
^]