EDIT:
Hi, trying an edit to get this question answered. In order to try improve the question, here is a straight to the point condensed version:
Is the code below the way to go when mapping value objects to separate tables using fluent nhibernate, or is there an alternative?
Hi,
For the purpose of this question I am using nhibernate fluently configured.
I'm steadily learning DDD but am after some clarification with the mapping of value objects. There seems to be a lot of information regarding mapping value objects as components. However I would like to normalise my database in some instances therefore would give the value object a persistence identity (which if I'm correct, doesn't violate DDD value object rules).
I have seen this question on SO, but would like a bit more info on how to setup and map the actual value object.
I am comfortable when mapping a value object to a table which represents the entity. For example mapping an address value object into the customer table as a component.
My query lies in when mapping a value object which i want to place in a separate table. Is the best way to map the value object using classmap like below? I am planing to ignore the Id it is purely there for nhibernate persistence.
public class Address
{
protected virtual int id {get;}
public virtual string firstLine {get;}
public virtual string city {get;}
public virtual string postcode {get;}
}
public class AddressMap : ClassMap<Address>
{
public AddressMap()
{
Id(x => x.Id);
Map(x=> x.firstline);
Map(x=> x.city);
Map(x=> x.postcode);
}
}
Thanks in advance.