El TecnoBaúl de Kiquenet

Kiquenet boring stories

Posts Tagged ‘automapper’

Propiedades Null y AutoMapper

Posted by kiquenet en 7 mayo 2012

Problemática de propiedades Null y AutoMapper:

Una posible solución:

Mapper.CreateMap<OrderItem, OrderItemDTO>()
      .ForMember(dest => dest.VersionId, options => options.MapFrom(orderitem => orderitem.Version == null ? (int?) null : orderitem.Version.VersionId))
      .ForMember(dest => dest.VersionName, options => options.MapFrom(orderitem => orderitem.Version == null ? null : orderitem.Version.VersionName))
      ;
Mapper.CreateMap() .ForMember(d => d.Country, opt => opt.MapFrom(o => (o.Address != null) ? o.Address.Country : "ADDRESS NOT SPECIFIED"))

Existen distintos blogs que comentan la problemática:

http://weblogs.asp.net/psteele/archive/2011/03/18/automapper-handling-null-members.aspx

http://codebix.com/posts/post/183412/Automapper-Mapping-objects-Part-1-of-7-NullSubsitution

http://chunkyinterface.wordpress.com/category/net/automapper/

Referencias:

http://stackoverflow.com/questions/3083654/automapper-null-properies

http://stackoverflow.com/questions/6359833/auto-mapper-null-refrence

http://automapper.codeplex.com/wikipage?title=Projection

Posted in .NET | Etiquetado: , | Leave a Comment »