c# - error in automapper with child type -


i'm having error during automapper in win app in c# row:

  config.createmap<t432, proc>()  .formember(d => d.tipo.cod_tipo , o => o.mapfrom(s => s.cod_tipo)) 

the error : expression 'd => d.tipo.cod_tipo' must resolve top-level member , not child object's properties. use custom resolver on child type or aftermap option instead.\r\nnome parametro: lambdaexpression"}

where

 class t432  {     public string cod_tipo { get; set; }  }  class proc   {     public tipo_proc tipo { get; set; }  }  class tipo_proc  {     public string cod_tipo { get; set; }  } 

how correct automapper?

thanks in advance

you need use custom type converter automapper cannot configure "nested" objects , sets top level properties, take @ example on automapper site https://automapper.codeplex.com/wikipage?title=custom%20type%20converters

here example:

mapper.createmap<string, datetime>().convertusing(new datetimetypeconverter());

public class datetimetypeconverter : itypeconverter<string, datetime> {     public datetime convert(string source)     {         return system.convert.todatetime(source);     } } 

this map string datetime object. can substitute own types , provide configuration within convert method.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -