I am getting this exception when I attempt to access an object that is stored in a property of my domain object. I have done some research and still do not understand why I am getting this error.
I have a very basic repository in which I am creating a session and then using a ICriteria query to fetch the first record from the list of results. My Connection domain object has one to many relationship mapped to Server. Why does the session not include the server as a proxy when it fetches the Connection object? I'm not very familiar session managment with NHibernate.
Here is my implementation:
Domain obj:
public class Connection {
public virtual int Id { get; private set; }
public virtual string FullName { get; set; }
public virtual string Email { get; set; }
public virtual string NickName { get; set; }
public virtual string Alternative { get; set; }
public virtual bool IsInvisible { get; set; }
public virtual Server CurrentServer { get; set; }
}
public Connection GetConnection()
{
using (ISession session = NHibernateHelper.OpenSession())
{
ICriteria crit = session.CreateCriteria(typeof(Connection));
crit.SetMaxResults(1);
IList<Connection> connection = crit.List<Connection>();
return connection[0];
}
}
The above will successfully return a Connection object. However accessing the CurrentServer property with throw the exception. It is/was my assumption that NHibernate was aware of the relationship that this object has with 'CurrentServer' and would therefore load that object, lazily, when requested. Can someone tell me where I was led astray?
Thanks!