I have the following Map created:
Mapper.CreateMap<UsuarioViewModel, GEN_USUARIOS>();
In this Map, there are some properties which are 'int?' (nullable foreign keys) as, for example IDSUPERVISOR.
In order to apply the mapping I use the following sentence:
Mapper.Map<UsuarioViewModel, GEN_USUARIOS>(usuarioVM, usuario);
- If source has value (5) and destination has not value (null), the value is applied to destination (5).
- If source has value (6) and destination has another value (5), the value is applied to destination correctly (6).
- But, if both have the same value (not modifying the value), the property in destination is mapped to NULL, which is wrong!
Is this a bug or there is something I'm missing?
EDIT: I've been able to isolate the problem in a simple project. I have created a repository in GitHub: https://github.com/farlop/TestAutomapper. It includes the code and a SQL script to create the database schema and sample data. To test it just lauch, edit the record which has value in IDSUPERVISOR column and just save without changing any data. You can see how the value is updated to null when it shouldn't