I have following domain model that I need to persist in database with help of Fluent NHibernate:
public class Entity
{
public Guid Id { get; set; }
public IValueObject AnyValueObject { get; set; }
}
public interface IValueObject
{
string Value { get; }
}
public class ValueObject : IValueObject
{
private readonly string _value;
public ValueObject(string value)
{
_value = value; // null checks omitted for brevity
}
public string Value { get { return _value; }}
}
public class AnotherValueObject : IValueObject
{
private readonly string _value;
private readonly string _anotherValue;
public AnotherValueObject(string value, string anotherValue)
{
_value = value; // null checks omitted for brevity
_anotherValue = anotherValue;
}
public string Value { get { return _value; } }
public string AnotherValue { get { return _anotherValue; } }
}
ValueObject and AnotherValueObject doesn't have any id and they're immutable.
The problem is that I have no idea how to write map for AnyValueObject property. I know that value objects must be mapped as Components, but how to deal with abstract immutable value objects?