Say I have a data model, which looks like this:
public class DataCustomer { public virtual System.DateTime CreatedTime { get; set; } public virtual Guid Id { get; set; } public virtual string FirstName { get; set; } public virtual string Surname { get; set; } public virtual string FaxNumber{ get; set; } public virtual System.DateTime DateOfBirth { get; set; } public virtual String Gender { get; set; } public virtual string UserID { get; set; } public virtual List<Offers> Offers { get; set; } }
This class is mapped to NHibernate. Now say I have a Domain Model like this:
public class DomainCustomer { private virtual Guid Id { get; set; } private virtual String Gender { get; set; } private virtual DateTime DateOfBirth { get; set; } public virtual List<Offers> Offers { get; set; } public DomainCustomer(Guid id, string gender, DateTime dateOfBirth) { Id=id; Gender=gender; DateOfBirth=dateOfBirth; } public void AssignOffers(IOfferCalculator offerCalculator, IList<Offers> offers) { //Assign the offers here } }
Notice that the Data Model looks different to the Domain Model. I believe this is normal practice, however every example I look at online seems to show the Data Model being the same as the domain model.
Option 1
The advantage of them being identical is that mapping between the Domain Model and Data Model is very simple i.e. you can do this with AutoMapper:
DataCustomer dataCustomer = AutoMapper.Mapper.Map<DataCustomer>(domainCustomer);
Option 2
The advantage of them being different is that there is less data passed between the data model and domain model and vice versa. Also I think that it makes it slightly clearer i.e. a user/reader of my class knows what fields are needed by the domain model. With this approach; I would only map the members that have changed i.e. offers:
customerData.Offers = AutoMapper.Mapper.Map<string>(customerDomain.Offers);
Decision
Both options use a factory when mapping between CustomerData and CustomerDomain. The question is about the mapping between CustomerDomain and CustomerData using AutoMapper.
Which option is more expected if I am following the principle of least astonishment?