Keeping Linq to SQL alive when using ViewModels (ASP.NET MVC)

Posted by Kohan on Stack Overflow See other posts from Stack Overflow or by Kohan
Published on 2010-05-04T12:12:55Z Indexed on 2010/05/04 12:18 UTC
Read the original article Hit count: 172

Filed under:
|
|
|

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.

© Stack Overflow or respective owner

Related posts about c#

Related posts about linq-to-sql