Hi,
I have a very simple question:
I have class Voter with ctor who supposed to get the object from DB.
The problom is that I did not succeded to fill the object 'this' itself because it's readonly. So what's i am doing now is fill another object (voterCopy) and then copy seperately field, field in 'copyValues' function.
How can I do it directly ?
public Voter()
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly("LocalElectionsDll");
ISessionFactory factory = cfg.BuildSessionFactory();
ISession session = factory.OpenSession();
Voter voterCopy;
try
{
ITransaction transaction = session.BeginTransaction();
voterCopy = (Voter)session.Get(typeof(Voter), vPK);
transaction.Commit();
this.copyValues(voterCopy);
}
}
private void copyValues(Voter srcVoter)
{
this.sFirstName = srcVoter.sFirstName;
this.sLastName = srcVoter.sLastName;
. . .
}
}
Thanks !
|