c# - Custom Mapping With Automapper Using Global.asax -


i have static mapper class called global.asax can map simple classes fine:

global.asax:

automapperconfiguration.configure(); 

automapperconfiguration:

configure() {   mapper.initialize(cfg => { cfg.createmap<tms.entity.coursesession, dataaccess.entities.coursesession>(); });   mapper.initialize(cfg => {     cfg.createmap<tms.entity.course, dataaccess.entities.course>() 

where coursesession nested object in course

public class course  {   public icollection<coursesession> coursesessioncoll; 

no matter seem in mapper throws error:

the following property on dataaccess.entities.coursesession cannot mapped: coursesessioncoll

it works if ignore property:

mapper.initialize(cfg => {             cfg.createmap<tms.entity.course, dataaccess.entities.course>()             .formember(o => o.coursesessioncoll, s => s.ignore()) 

but if try map it throws error.

edit - added example of classes

the property in classes in named same , have mapping these preceding of map:

namespace tms.entity {   public class course   {     public icollection<coursesession> coursesessioncoll { get; set; }     ...  ------------------------------------------------  namespace dataaccess.entities {   public class course   {     public icollection<coursesession> coursesessioncoll { get; set; } 

the problem calling initialize method twice , second call overrides first configuration. need add more maps in same configuration instead of calling multiple times initialize method:

mapper.initialize(cfg => {  cfg.createmap<tms.entity.coursesession, dataaccess.entities.coursesession>(); cfg.createmap<tms.entity.course, dataaccess.entities.course>(); }); 

Comments