c# - AutoMapper Take Properties from Child -


my model similar following:

public class source {     public string property1 { get; set; }     public string property2 { get; set; } }  public class sourcecontainer {     public source source { get; set; }     public string extradata { get; set; } }  public class sourceviewmodel {     public string property1 { get; set; }     public string property2 { get; set; }     public string extradata { get; set; } }  mapper.createmap<source, sourceviewmodel>(); 

when want map source sourceviewmodel, fine , don't have extradata populated. want map sourcecontainer sourceviewmodel, preferably without specifying mapping each property.

is possible tell automapper import properties child property, source, when doing mapping? like:

mapper.createmap<sourcecontainer, sourceviewmodel>()     .usemappingforproperty(x => x.source); 

otherwise can tell automapper each property on sourceviewmodel separately , child source, i'm wondering if there's more elegant approach.

i use .constructusing initialize resulting sourceviewmodel results of mapping inner source property:

mapper.createmap<sourcecontainer, sourceviewmodel>()     .constructusing(container => mapper.map<sourceviewmodel>(container.source)); 

extradata mapped conventially after sourceviewmodel constructed.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -