У меня есть следующая структура запросов и ответов:
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; }
}
}
}
, и я хочу сопоставить ее со следующей структурой DTO:
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; }
}
Отображение будет следующим:
Action.Create.Request.operationdate
=> ActionModelDTO.ActionDate
Action.Create.Request.action
=> ActionDetailModelDTO.ActionType
Action.Create.Request.identificationaccount
=> ActionUserDetailModelDTO.UserAccount
Action.Create.Request.observation
=> ActionUserDetailModelDTO.UserObservation
Объект, на который вам нужно будет нанести картуGroupDTO ... это первый раз, когда я использую Automapper, и он возвращает следующую ошибку:
Найдены несопоставленные элементы.Просмотрите типы и членов ниже.Добавление пользовательского выражения сопоставления, игнорирование, добавление настраиваемого преобразователя или изменение типа источника / назначения. Если нет подходящего конструктора, добавьте c-аргумент без аргументов, добавьте необязательные аргументы или сопоставьте все параметры конструктора
Поля, которые не отображаются в указанном мэппинге, заполняются после того, как объект сохраняется в БД.
С уважением!