2017-08-07 71 views
0

源類有2個屬性,目標類3屬性,映射,我認爲在目標類中有1個屬性不變,我使用NotMapped,但沒有成功,但是NotMapped不是我想要的方式,你做什麼?Automapper映射,如何使字段未映射

class AAA 
{ 
    public string Name { set; get; } 
    public string Id { set; get; } 
    public string Remark { set; get; } 
} 

class AAAViewModel 
{ 
    public string Name { set; get; } 
    public string Id { set; get; } 
} 

protected override MapperConfiguration Configuration => new MapperConfiguration(cfg=> 
{   
    cfg.CreateMap<AAA, AAAViewModel>(MemberList.Destination); 
    cfg.CreateMap<AAAViewModel, AAA>(MemberList.Source); 
}); 

[Fact] 
public void test() 
{ 
    AAA a = new AAA() { Id = "1", Name = "name1", Remark = "remark1" }; 
    var avm = Mapper.Map<AAAViewModel>(a); 
    AAA b = new AAA() { Remark = "remakrb" }; 
    b = Mapper.Map<AAA>(avm); 
    Assert.Equal(avm.Id, "1"); 
} 

回答

0

該屬性被稱爲IgnoreMap。