Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finally ended up getting this to work on my own. The code I ended up using is posted below. Creating the map of objects in the correct order proved to be important. I learned a lot fighting through this thing. </p> <p>I've organized my mappings into a profile, which I won't get into here, suffice to say that if you can use my example outside of a class inheriting from the AutoMapper Profile class, you'll want to use Mapper.CreateMap instead of just Create Map.</p> <pre><code> private void CreateMaps() { CreateMap&lt;ContactEntity, TransfereeEntityDto&gt;(); //ContactEntity Mapping CreateMap&lt;ContactEntity, TransfereeEntityDto&gt;(); //CustomerEntity Mapping CreateMap&lt;CustomerEntity, CustomerEntityDto&gt;(); //AddressEntity Mapping CreateMap&lt;AddressEntity, AddressEntityDto&gt;(); //ServiceEntity Mapping CreateMap&lt;ServiceEntity, ServiceEntityDto&gt;() .ForMember(dto =&gt; dto.ServiceTypeCode, opt =&gt; opt.MapFrom(source =&gt; source.TypeCode)) .ForMember(dto =&gt; dto.ServiceDescriptionCode, opt =&gt; opt.MapFrom(source =&gt; source.DescriptionCode)) .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)); //VehicleEntity Mapping CreateMap&lt;VehicleEntity, VehicleEntityDto&gt;() .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)) .ForMember(dto =&gt; dto.PortalId, option =&gt; option.Ignore()); //TODO: Should PortalID be mapped to anything? It is not in the entity. //ContentEntity Mapping CreateMap&lt;ContentEntity, ContentEntityDto&gt;() .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)); //OrderForwardingEntity Mapping CreateMap&lt;OrderForwardingEntity, OrderForwardingEntityDto&gt;(); //ContainerEntity Mapping CreateMap&lt;ContainerEntity, ContainerEntityDto&gt;() .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)); //ShipmentForwardingEntity Mapping CreateMap&lt;ShipmentForwardingEntity, ShipmentForwardingEntityDto&gt;(); //ShipmentRouting Mapping CreateMap&lt;ShipmentRoutingEntity, ShipmentRoutingEntityDto&gt;(); //ShipmentEntity Mapping CreateMap&lt;ShipmentEntity, ShipmentEntityDto&gt;() .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)) .ForMember(dto =&gt; dto.Services, option =&gt; option.MapFrom(source =&gt; source.ServiceEntities)); //Forwarder mapping CreateMap&lt;ContactEntity, ForwarderEntityDto&gt;(); //TODO: This property doesn't have any properties in the data contract //OrderEntity Mapping CreateMap&lt;OrderEntity, OrderEntityDto&gt;() .ForMember(dest =&gt; dest.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)); //.ForMember(dto =&gt; dto.Forwarder, option =&gt; option.MapFrom(entity=&gt;entity.Forwarder) //MoveEntityMapping CreateMap&lt;MoveEntity, MoveEntityDto&gt;() .ForMember(dto =&gt; dto.SourceSystemName, opt =&gt; opt.ResolveUsing&lt;SourceSystemNameResolver&gt;().FromMember(entity =&gt; entity.SourceSystemName)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload