bstack
unread,Oct 22, 2008, 7:01:42 AM10/22/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to nhusers
All,
We are using immutable types in our domain, that we want to map
directly to to database. The type takes the following format:
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?