I have the following Request and Response structure:
public class Action
{
public class Create
{
public class Request
{
public string operationdate { get; set; }
public string action { get; set; }
public string identificationaccount { get; set; }
public string observation { get; set; }
private ErrorModel.Error errorrow = new ErrorModel.Error();
public ErrorModel.Error ErrorRow { get { return errorrow; } set { errorrow = value; } }
}
public class Response : Request
{
public Int32 version { get; set; }
public string groupcode { get; set; }
public bool active { get; set; }
}
}
}
and I want to map to the following DTO structure:
public class GroupDTO
{
public Int64 idGroup { get; set; }
public string GroupCode { get; set; }
public string GroupDate { get; set; }
public string Obs01 { get; set; }
public string Obs02 { get; set; }
public string Obs03 { get; set; }
public string Obs04 { get; set; }
public bool Active { get; set; }
private List<ActionModelDTO> _Actions = new List<ActionModelDTO>();
public List<ActionModelDTO> Actions { get { return _Actions; } set { _Actions = value; } }
}
public class ActionModelDTO
{
public Int64 idAction { get; set; }
public string ActionDate { get; set; }
public Int32 Version { get; set; }
public Int32 idGroup { get; set; }
public bool Active { get; set; }
private ActionDetailModelDTO _ActionDetailModel = new ActionDetailModelDTO();
public ActionDetailModelDTO ActionDetailModel { get { return _ActionDetailModel; } set { _ActionDetailModel = value; } }
private ActionUserDetailModelDTO _ActionUserDetailModel = new ActionUserDetailModelDTO();
public ActionUserDetailModelDTO ActionUserDetailModel { get { return _ActionUserDetailModel; } set { _ActionUserDetailModel = value; } }
}
public class ActionDetailModelDTO
{
public Int64 idActionDetailModel { get; set; }
public Int32 idActionType { get; set; }
public string ActionType { get; set; }
}
public class ActionUserDetailModelDTO
{
public Int64 idActionUserDetailModel { get; set; }
public string UserAccount { get; set; }
public string UserObservation { get; set; }
public string IdentificationNumber { get; set; }
}
The mapping would be as follows:
The object to which you would have to map is GroupDTO ... it is the first time I use Automapper, and it returns the following error:
Unmapped members were found. Review the types and members below. Add a custom mapping expression, ignore, add to custom solve, or modify the source / destination type For no matching constructor, add a no-arg ctor, add optional arguments, or map all of the builder parameters
The fields that do not appear in the mapping that I specified are completed after the object persists in DB.