views:

79

answers:

1

hey folks,

I have my NHibernate mappings set to lazy loading = true. In my CustomersViewModel I have something like:

        foreach (Customer c in _customerRepository)
        {
            this.Customers.Add(new SingleCustomerViewModel(c));
        }

This obviously kills all the lazy loading, since the customers are passed one by one.

How do I get my collections (including subcollections and sub-subcollections a.s.f.) of model-objects into the corresponding ObservableCollections of my ViewModels to bind to the UI?

This seems to be a common problem, but I found no answer, neither here nor on the Googles ...

+3  A: 

I am not sure I completely understand the question . But I was thinking why not change your getCustomers method to

 IEnumerable<SingleCustomerViewModel> getCustomers(){
     return  from c in _customerRepository select SingleCustomerViewModel(c);
  }

Since LINQ expressions are lazily evaluated you nhibernate collection wont be initialized until its actually bound to the UI .

Surya