3

I just started using ValueInjecter for my Entity Mappings(DTO <-> Entity). Heres my DTO :

public class IncidentDTO
{
    int ID { get; set; }
    string Name { get; set; }
    AgencyDTO agencyDTO { get; set; }
}

public class AgencyDTO
{
    int ID { get; set; }
    string Name { get; set; }
    List<IncidentTypeDTO> incidentTypeDTOList { get; set; }
}

public class IncidentTypeDTO
{
    int ID { get; set; }
    string TypeName { get; set; }
}

Heres my NHibernate Proxy classes :

 public class Incident
{
    int ID { get; set; }
    string Name { get; set; }
    Agency agency { get; set; }
}

public class Agency
{
    int ID { get; set; }
    string Name { get; set; }
}

public class IncidentType
{
    int ID { get; set; }
    string TypeName { get; set; }
}

public class AgencyIncidentType
{
    int ID { get; set; }
    Agency agency { get; set; }
    IncidentType incidentType { get; set; }
}

Now, I need to query IncidentDTO from Repository. Repository query Incident & AgencyIncidentType tables from database and map Incident -> IncidentDTO using ValueInjecter and return IncidentDTO.

What is the best possible way to do the above mapping using ValueInjecter??

Thanks, Prateek

Prateek Singh
  • 863
  • 1
  • 8
  • 28
  • 1
    look at http://prodinner.codeplex.com, it uses valueinjecter for the exact same thing that you are doing, it also has a pdf explaining that – Omu Jun 25 '12 at 21:17
  • Thanks Chuck!! thats exactly what i was looking for, `ConventionInjection` for `IEnumerable` types.... Also @Gloppy's answer pointed me to Deep Cloning + `ConventionInjection for IEnumerable` so i am marking it as answer.. Thanks guys for help!! and Chuck for making object-object mapping so much easier..;) – Prateek Singh Jun 26 '12 at 02:27

1 Answers1

4

If you want to map Incident to IncidentDTO while retaining and mapping the Agency object in the agency property (to an AgencyDTO) of an Incident instance I'd suggest renaming the agencyDTO property to agency in your IncidentDTO and then use a tweak to the CloneInjection sample from the Value Injector documentation as described here: omu.valueinjecter deep clone unlike types

Community
  • 1
  • 1
Gloopy
  • 37,767
  • 15
  • 103
  • 71