c# - mapping complex object with automapper -


how can convert ienumerable<category> ienumerable<categoryviewmodel> definition

public class category     {         public guid id { get; set; }         public string name { get; set; }         public datetime creationtime { get; set; }      }  public class categoryviewmodel {     public guid  categoryid { get; set; }     public string name { get; set; } } 

i have done

public static ienumerable<categoryviewmodel> converttocategoryviewmodellist(this ienumerable<category> category)         {             return mapper.map<ienumerable<category>, ienumerable<categoryviewmodel>>(category); 

but doesn't map id categoryid , don't want have creationtime in categoryveiwmodel

either property names should match, or have override mapping id. have explicitly ignore creationtime:

automapper.mapper.createmap<category, categoryviewmodel>() .formember(x => x.categoryid, src => src.mapfrom(y => y.id)) .forsourcemember(x => x.creationtime, y => y.ignore()); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -