c# - Mapping class to a Model containing Models using AutoMapper -


i have view model:

public class itemviewmodel {     public guid id { get; set; }     public itemgeneraldetailsviewmodel generaldetails { get; set; }     public itemfinancialdetailsviewmodel financialdetails { get; set; }      public itemviewmodel()     {         generaldetails = new itemgeneraldetailsviewmodel();         financialdetails = new itemfinancialdetailsviewmodel();         generaldetails.properties = new itempropertiesviewmodel();     } } 

and have class domain class:

public class item {     public item();      public bool? isserialitem { get; set; }     public bool? issalesitem { get; set; }     public byte isregistrationcodeitem { get; set; }     public bool? ispurchaseitem { get; set; }     public bool? ispackageitem { get; set; }     public byte isondemanditem { get; set; }     public byte isnewcontract { get; set; }     public byte ismakeitem { get; set; }     public bool? isfractionalloweditem { get; set; }     public bool? isserialnumberitem { get; set; }     public byte isbatchnumberitem { get; set; }     public guid id { get; set; }     public double? grossweight { get; set; }     ...     ... } 

i trying make mapping configuration automapper in order map directly item view model,

var model = mapper.map<item,itemviewmodel>(someitem); 

the properties in each of models have corresponding property in item, hence there no configuration regarding naming of properties.

hence can like:

var generaldetailsmodel = mapper.map<item,generalitemdetailviewmodel>(someitem); ... var itemmodel = new itemviewmodel {   generaldetail = generaldetailsmodel;   ...   ... } 

so, question is: there way can configure automapper maps models inside model?

the configuration:

public static class automapperconfiguration {     public static void configure()     {         mapper.initialize(cfg =>         {             cfg.addprofile(new webprofile());             ...         });       } }  public class webprofile : profile {     public webprofile()     {         // want make configuration configured in such manner         createmap<item, itemviewmodel>();        ...      }  } 


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -