I have the following code to update Student
entity:
using static AutoMapper.Mapper;
...
public void Update(StudentInputDto dto)
{
Student student = _studentRepository.GetStudent();
student = Map<Student>(dto); //student.studentnumer is null here :(
_studentRepository.Update(student);
}
My student Entity:
public class Student
{
public Guid studentid { get; set; }
public string firstname { get; set; }
public string lastname { get; set; }
public int age { get; set; }
public Guid genderid { get; set; }
public string studentnumber { get; set; }
}
My StudentInputDto:
public class StudentInputDto
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public Guid GenderId { get; set; }
}
The problem is that Student.studentnumber is null after the mapping.
I want to configure AutoMapper in such a way that Student.studentnumber is preserved after the mapping. How to do it ? Any help would be greatly appreciated.
My initial thought was to configure AutoMapper in a following way:
Mapper.Initialize(cfg => {
cfg.CreateMap<StudentInputDto, Student>()
.ForMember(dest => dest.studentnumber, opt => opt.Ignore());
});
But that configuration, does not solve the problem.