首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Automapper

使用Automapper
EN

Stack Overflow用户
提问于 2013-02-04 22:19:55
回答 1查看 76关注 0票数 0

我有一个客户端类,我需要将它映射到一个不太复杂的clientViewModel类,下面是两个类:

代码语言:javascript
复制
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;}
 }

代码语言:javascript
复制
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; }       
}

这就是我映射模型的方式(它仍然是一个概念的证明)

代码语言:javascript
复制
        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);

问题出在视图上,我可以看到名称和标题,但看不到地址。还有没有我应该做的其他映射?不要确保address行1中的内容映射到clientViewModel类的Line1?

谢谢

EN

回答 1

Stack Overflow用户

发布于 2013-02-05 19:35:43

来自评论

在这里看一下:或者你可以创建一个自定义的解析器..

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14688650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档