Please see the domain object below:
public Class Person
{
public virtual Guid Id { get; protected set; }
public virtual string FirstName { get; protected set; }
public virtual string Surname { get; protected set; }
public virtual System.DateTime DateOfBirth { get; protected set; }
//Domain methods are here.
}
and the NHibernate mappings below:
public class PersonMap : ClassMapping<Person>
{
public PersonMap()
{
Id<Guid>(x => x.Id);
Property<string>(x => x.FirstName);
Property<string>(x => x.Surname);
Property<DateTime>(x => x.DateOfBirth);
}
}
This works as expected. Say I wanted to change the domain model to this:
public Class Person
{
public virtual Guid Id { get; protected set; }
public virtual FirstName FirstName { get; protected set; }
public virtual Surname Surname { get; protected set; }
public virtual DateOfBirth DateOfBirth { get; protected set; }
}
Notice the primitive types are replaced with objects. The reason I am doing this is to remove primitive obsession as described here: http://enterprisecraftsmanship.com/2015/03/07/functional-c-primitive-obsession/
I have read the documentation here (page 144): http://stc.sbu.ac.ir/AdminTools/Docs/Files/nhibernate_reference.pdf. It is telling me to introduce a custom type. I have also read this question: nHibernate mapping to custom types. I am still struggling to do this with NHibernate code mapping and hence the reason for the question.