Keeping Linq to SQL alive when using ViewModels (ASP.NET MVC)
- by Kohan
I have recently started using custom ViewModels (For example, CustomerViewModel)
public class CustomerViewModel
{
public IList<Customer> Customers{ get; set; }
public int ProductId{ get; set; }
public CustomerViewModel(IList<Customer> customers, int productId)
{
this.Customers= customers;
this.ProductId= productId;
}
public CustomerViewModel()
{
}
}
... and am now passing them to my view instead of the Entities themselves (for example, var Custs = repository.getAllCusts(id) ) as it seems good practice to do so.
The problem i have encountered is that when using ViewModels; by the time it has got to the the view i have lost the ability to lazy load on customers. I do not believe this was the case before using them.
Is it possible to retain the ability of Lazy Loading while still using ViewModels?
Or do i have to eager load using this method?
Thanks,
Kohan.