I am using fluent nhibernate. This is code Loads an instance of type T from the DB based on its ID.
public T GetById(IdT id, bool shouldLock)
{
T entity;
if (shouldLock)
{
entity = (T) NHibernateSession.Load(persitentType, id, LockMode.Upgrade);
}
else
{
entity = (T) NHibernateSession.Load(persitentType, id);
}
return entity;
}
but i have big problem. When i call property on it i get ObjectNotFoundException instead of null. How can i make that entity will be nullable and not return exception?