Error handling when ABP specifies map object during map operation

Error handling in map operation of ABP

When mapping an entity object into dto in ABP, the entity defines an object of type long. In dto, there is an object with the same name, but the type is guid,

// StudentEntity
public class StudentEntity
{
		public Guid RelatedStudentId
		{
				get; set;
		}
}

// StudentDto
public class StudentDto
{
		public Guid StudentId
		{
				get;  set;
		}
		
		public Long RelatedStudentId
		{
				get; set;
		}
}

Take studententity and studentdto for example. Due to the change of business, when the back-end modifies the database and does not change the front-end code for the time being,

Directly map the relatedpatientid in entity to the studentID in dto , In this way, an error will occur when mapping, indicating that the type conversion error is wrong, and the data of the guid cannot be assigned to long,

CreateMap<StudentEntity, StudentDto>()
            .ForMember(d => d.StudentId, map => map.MapFrom(o => o.RelatedStudentId))

At this time, the entity’s guid type relatedpatientid will be mapped to the long type relatedpatientid in dto,

This kind of data definition should be avoided in map operation.

Read More: