0

我有一个客户端类,我需要将其映射到一个不太复杂的 clientViewModel 类,这里有两个类:

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);

问题出在视图上,我可以看到名称和标题,但看不到地址。我应该做任何其他映射吗,确保地址类 1 odf 中的任何内容都映射到 clientViewModel 类的 Line1?

谢谢

4

1 回答 1

1

从评论中

看看这里: http: //github.com/AutoMapper/AutoMapper/wiki/Nested-mappings或者你可以创建一个自定义解析器.. http://github.com/AutoMapper/AutoMapper/wiki/Custom-value-resolvers

于 2013-02-05T11:35:42.520 回答