Hi,
I have a project where i am using repositories to access my data with
nhibernate.
So I have an IRepository<TDomain, TKey> interface and its
implementation.
This repository is from CodeSmith template and it has incapsulated
session management from that template.
Now when I want to use it I do:

public Person GetPersonById(int id)
{
   Person person = null;
   using (var rep = ObjectFactory.GetInstance<IRepository<Person,
int>>())
   {
       person = rep.GetById(1);
   }
   return person;
}

now I have the person object but the problem is this:
the Person class has a collection of Addresses that is lazy
initialized.
So when in the code I do:

Person person = GetPersonById(1);
foreach(var address in person.Addresses)
{...}

I get lazy initialization exception because there is no more session
open.

What must I do,  how must I use this repository so I wont get lazy
exceptions?



-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to