I am trying to understand why this is not working ...
Domainmodel
public class ModelEntities : DbContext
{
public DbSet<Address> Addresses { get; set; }
}
controller
public ViewResult List(int id)
{
var db = new ModelEntities();
var addresses = db.Addresses.Where(x => x.CustomerID == id).AsEnumerable();
return View(entities.Cast<AddressVM>());
}
View
@model IEnumerable<WebUI.Models.AddressVM>
...
AddressVM
public class AddressVM
{
public AddressVM(Address address) { Bind(address); }
private void Bind(Address address)
{
}
public static explicit operator AddressVM(Address address)
{
return new AddressVM(address);
}
}
Now, if I changed my mind to accept IEnumerable<DomainModel.Models.Address>
, and not complete the throw, everything works as expected.
When I try to roll, I get the following error:
Unable to transfer object of type "System.Data.Entity.DynamicProxies.Address_37444C79F0AB1E0A599C8797F37448F12213C5BCAC0611B4C1C8EFADDEFAA82C" for input "WebUI.Models.AddressVM".
In the controller, why is there a addresses
set of dynamic proxies even after a call AsEnumerable()
? What do I need to do to get a collection of objects in my domain model so that I can apply them to the view model?