0
我有我需要映射到一個配合物類clientViewModel少一個客戶端類,這裏是兩類:使用Automapper
public class client
{
public int clientRef{get;set;}
public string Title{get;set;}
public string Forename { get; set; }
public string Initials { get; set; }
public string Surname { get; set; }
Public Address address{get;set;}
}
和
public class ClientsViewModel
{
public int ClientRef { get; set; }
public string Title { get; set; }
public string Forename { get; set; }
public string Initials { get; set; }
public string Surname { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Line3 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string Postcode { get; set; }
public string Country { get; set; }
}
這對我是怎麼映射模型(這是剛纔還在概念證明)
IList<ClientsViewModel> _clientsViewModelsclients = new List<ClientsViewModel>();
var model =
new Clients().Get(10);
Mapper.CreateMap<Client, ClientsViewModel>();
ClientsViewModel cv = Mapper.Map<Client, ClientsViewModel>(model);
_clientsViewModelsclients.Add(cv);
return View(_clientsViewModelsclients);
THR問題上的看法,我可以看到姓名和職務,但試驗時他地址。有沒有其他的映射,我應該做的,確保無論是在地址線1 odf地址類映射到clientViewModel類的Line1?
感謝
到這裏看看:https://開頭github.com/AutoMapper/AutoMapper/wiki/Nested-mappings或者你可以創建一個自定義的解析器.. https://github.com/AutoMapper/AutoMapper/wiki/Custom-value-resolvers – TryingToImprove
非常感謝@ TryingToImprove –