Quote:
the profile loading throw a lazyinitialisationexception but the code to load user don't throw exception.
I have added a line of code in catch
Code:
catch (System.Exception)
{
user = null;
throw;
}
When I load the user, the code go in finally section and when I quit the function, my user is not null, so the line code "user = null" isn't executed.
But, if I try to use the user object after the function call, I get an ObjectNotFoundException.
I see that the user has several null values in properties (apart default values).
If I "spy" the profile property of the user, C# show me a lazyinitializationException.
To resolve the problem, I have added another line code:
model.ProfilesEntity profil = user._profile;
Code:
UsersEntity user = null;
try
{
try
{
user = session.Load(typeof(model.UsersEntity), Id) as model.UsersEntity;
model.ProfilesEntity profil = user._profile;
}
catch (NHibernate.ObjectNotFoundException)
{ user = null; }
catch (System.Exception)
{ user = null; }
}
finally
{
session.Close();
}
return user;
The of profile property throw the exception and my object is null after call the function.