c# - AutoMapper Profiles: flattening a dto for mapping -


i have main class has nested class. have used map using mapper class

public class main {     public string name { get; set; }     public list<quantitylocation> nc { get; set; } }  public class nestedclass {     public decimal b { get; set; }     public string { get; set; } }  public class flattened {     public string name { get; set; }      public string { get; set; }     public decimal b { get; set; } } 

mapping done using mapper class below.

    mapper.createmap<nestedclass, flattened>();     mapper.createmap<main, flattened>();     mapper.createmap<main, list<flattened>>()         .convertusing(i =>                 i.nc.select(                     flat =>                     {                         var flatlist = mapper.map<flattened>(i);                         mapper.map(flat, flatlist);                         return flatlist;                     }).tolist()); 

now when moved mapping profile class, had change lines above below:

createmap<nestedclass, flattened>(); createmap<main, flattened>(); createmap<main, list<flattened>>()     .convertusing(i =>             i.nc.select(                 flat =>                 {                     var flatlist = mapper.map<flattened>(i);                     mapper.map(flat, flatlist);                     return flatlist;                 }).tolist()); 

the problem facing how convert these 2 lines below in snippet above.

               var flatlist = mapper.map<flattened>(i);                 mapper.map(flat, flatlist); 

you see injecting mapper.engine constructor of controllers. earlier using static mapper class used called in global.asax. error 1 below.

missing type map configuration or unsupported mapping.  mapping types: main -> list`1 myproj.main -> system.collections.generic.list`1[[myproj.flattened, myproj, version=1.0.0.0, culture=neutral, publickeytoken=null]]  destination path: list`1  source value: myproj.main 

the proper way use custom type converter, in inject mapping engine itself. , use constructservicesusing in profile declaration.

assuming use of ioc container, , have registered in mapping engine, , custom type converter, inside converter use engine.map instead static mapper.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -