All,
We are using immutable types in our domain, that we want to map
directly to to database. The type takes the following format:
Code:
public class X
{
private readonly int m_Prop1;
private readonly int m_Prop2;
private X() { }
public X(int p1, int p2)
{
//Perform validation guard check against arguments
this.m_Prop1 = p1;
this.m_Prop2 = p2;
}
public int Prop1 { get { return this.m_Prop1; } }
public int Prop2 { get { return this.m_Prop2; } }
}
The problem we have is that the private constructor is what NHibernate
instantiates (not the public constructor where guard checks are
performed), hence we can end up "getting" an instance of X from the
database that is invalid.
Is there any way to get NHibernate to call the constructor that
performs the guard checks?
Any help with this will be greatly appreciated.