title: Object mapper vs Object wrapper
body: <p>I would appreciate a little help here...</p>
  
  <p>Lets say that in an application we have a Data Layer and a Business Logic Layer. In the DAL we have the following entity:</p>
  
  <pre><code>public class Customer {
      public string Name {get; set;}
      public ICollection&lt;Address&gt; Addresses {get; set;}
  }
  
  public class Address {
      public string Street {get; set;}
  }
  </code></pre>
  
  <p>In the BLL we have the following POCOs:</p>
  
  <pre><code>public class CustomerDto {
      public string Name {get; set;}
      public ICollection&lt;AddressDto&gt; Addresses {get; set;}
  }
  
  public class AddressDto {
      public string Street {get; set;}
  }
  </code></pre>
  
  <p>The entities in the DAL are populated with a ligth-weight ORM and retrieve from the BLL using a repository. Ex:</p>
  
  <pre><code>public class CustomerInformationService {
  
      private readonly ICustomerRepository _repository {get; set;}
      public CustomerInformationService (ICustomerRepository repository)
      {
           _repository = repository;
      }
      public class CustomerDto Get(int id)
      {
           var customerEntity = _repository.Get(id);
  
           var customerDto = /* SOME TRANSFORMATION HERE */
  
           return customerDTO;
      }
  }
  </code></pre>
  
  <p>My questions is about the /* SOME TRANSFORMATION HERE */ part. There is a discussion in our team about how to do the "mapping". </p>
  
  <p>One approach is to use a mapper either an automapper or a manual mapping.
  The second approach is to use sort of like a wrapper around Entity and reference the DTO in order to save a copying operation between object. Something like this:</p>
  
  <pre><code>public class CustomerDto
  {
       private IEntity _customerEntity;
  
       public IEntity CustomerEntity { get {return _customerEntity;}}
  
       public CustomerDto(IEntity customerEntity)
       {
            _customerEntity = customerEntity;
       }
  
       public string Name 
       { 
            get { return _customerEntity.Name; }
       }
       public ICollection&lt;Address&gt; Addresses 
       { 
            get { return _customerEntity.Addresses; }
       }
  }
  </code></pre>
  
  <p>The second approach feels a little weird to me because _customerEntity.Addresses feels like a leak (_customerEntity's reference) between my DAL and my BLL but I am not sure.</p>
  
  <p>Are there any advantages/disavantages of using one approach over the other one?</p>
  
  <p>Additional info: We usually pull a max. of 1000 records at a time that would need to be transform between Entity and DTO.</p>