Index du Forum

 FAQFAQ   RechercherRechercher   MembresMembres   GroupesGroupes   S’enregistrerS’enregistrer 
 ProfilProfil   Se connecter pour vérifier ses messages privésSe connecter pour vérifier ses messages privés   ConnexionConnexion 


Poster un nouveau sujet   Répondre au sujet     Index du Forum -> Les bureaux -> Dame Quasi
Sujet précédent :: Sujet suivant  
Auteur Message

Hors ligne

MessagePosté le: Sam 25 Nov - 07:24 (2017)    Sujet du message: Forums Répondre en citant

I am in the process of a refactor and utilizing AutoMapper (6.2.1) to help us in formatting of API returns that conform to a specific contract. The DTO objects we are using internally are meant to simplify our understanding of the data before returning the data in the more complex type.

The Issue: I have a DTO with a List<T> where I need one of the properties of <T> to be mapped to the collection in the more complex type. This is actually pretty straight forward but the problem is, what if the collection Android I am trying to map to in the more complex type is in fact inside another "higher" collection. Essentially I am in a little bit of a collection inside a collection problem.

public class ItemDTO
List<ItemDescriptionDTO> ItemDescriptions { get; set; }

public class ItemDescriptionDTO
public string Description { get; set; }
More Complex object I need to map to and do not have control over

public class ComplexThing // This is the object I need (It's ugly, I hate it too)
public ComplexItemDescriptions { get; set; }

public class ComplexItemDescriptions
public List<ComplexItemDescription> ComplexItemDescription { get; set; }

public class ComplexItemDescription
public UnparsedItemDescriptions UnparsedItemDescriptions { get; set; }

public class UnparsedItemDescriptions
public List<UnparsedItemDescription> UnparsedItemDescription { get; set; }

public class UnparsedItemDescription
public string UnparsedItemDescription { get; set; }
In essence I need to take the Description in my simple ItemDescriptionDTOand map that through this awful chain of nested objects to set the UnparsedItemDescription

I am able to properly map from UnparsedItemDescription all the way to the ComplexItemDescription but going higher than that to the Complex thing is giving me some trouble.

This is the mapping I have so far:

config.CreateMap<ItemDescriptionDTO, UnparsedItemDescription>()
.ForMember(dest => dest.UnparsedItemDescription, map => map.MapFrom(src => src.Description));

config.CreateMap<ItemDTO, UnparsedItemDescriptions>()
.ForMember(dest => dest.UnparsedItemDescription, map => map.MapFrom(src => src.ItemDescritpions));

config.CreateMap<ItemDTO, ComplexItemDescription>()
.ForPath(dest => dest.UnparsedItemDescriptions.UnparsedItemDescription, map => map.MapFrom(src => src.ItemDescriptions));

// This is where we start failing (I think I am just not understanding something fundamental to how Automapper does things or I am up against some silly edge case
config.CreateMap<ItemDTO, ComplexItemDescriptions>()
.ForMember(dest => dest.ComplexItemDescription, map => map.MapFrom(src => ItemDescriptions));
I need the ComplexThing because there are other properties in that class that are returned so I can't just get away with returning say a ComplexItemDescription

I would appreciate an assistance you could give. I admittedly have a base understanding on how Automapper works (which I am in the process of trying to get better at) but this is really throwing me at the moment.
Revenir en haut

MessagePosté le: Sam 25 Nov - 07:24 (2017)    Sujet du message: Publicité

PublicitéSupprimer les publicités ?
Revenir en haut
Montrer les messages depuis:   
Poster un nouveau sujet   Répondre au sujet     Index du Forum -> Les bureaux -> Dame Quasi Toutes les heures sont au format GMT + 2 Heures
Page 1 sur 1

Sauter vers:  

Index | Panneau d’administration | créer un forum | Forum gratuit d’entraide | Annuaire des forums gratuits | Signaler une violation | Conditions générales d'utilisation
Powered by phpBB © 2001, 2018 phpBB Group
Traduction par : powered by ArgenBLUE free template