Вот моя передача данных объектапередача DTO в ViewModel
public class LoadSourceDetail
{
public string LoadSourceCode { get; set; }
public string LoadSourceDesc { get; set; }
public IEnumerable<ReportingEntityDetail> ReportingEntity { get; set; }
}
public class ReportingEntityDetail
{
public string ReportingEntityCode { get; set; }
public string ReportingEntityDesc { get; set; }
}
А вот мой ViewModel
public class LoadSourceViewModel
{
#region Construction
public LoadSourceViewModel()
{
}
public LoadSourceViewModel(LoadSourceDetail data)
{
if (data != null)
{
LoadSourceCode = data.LoadSourceCode;
LoadSourceDesc = data.LoadSourceDesc;
ReportingEntity = // <-- ? not sure how to do this
};
}
#endregion
public string LoadSourceCode { get; set; }
public string LoadSourceDesc { get; set; }
public IEnumerable<ReportingEntityViewModel> ReportingEntity { get; set; }
}
public class ReportingEntityViewModel
{
public string ReportingEntityCode { get; set; }
public string ReportingEntityDesc { get; set; }
}
}
Я не знаю, как передать данные из LoadSourceDetail ReportingEntity для LoadSourceViewModel ReportingEntity. Я пытаюсь передать данные из одного IEnumerable в другой IEnumerable.
Я использую automapper для всех моих отображений и из ViewModels –
спасибо за предложение, но я «Мне нравится знать, как это сделать« вручную »без AutoMapper. –
Нет проблем, для меня это был бы старомодный DTO с методом To() и From(). Я оставлю свой ответ там, так как сейчас я это сделаю. – hutchonoid