I am using MVC4 in my project along with EntityFramework (DB first approach). I am using automapper for the mapping of entity to model and vice versa.
Lazy loading and Dynamic proxies are enabled in my edmx.
Now I have defined all the mappings, but still whenever I try to get a list of records from entity and map it to view model, it throws an exception saying:
AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
RoutingRule -> RoutingViewModel
Iris.Models.Configuration.RoutingRule -> Iris.Web.Configuration.ViewModels.RoutingViewModel
Destination path:
List`1[0]
Source value:
System.Data.Entity.DynamicProxies.RoutingRule_9573 94C799768B52964A1F1E461B16DD867B73929DE4FE2873D65D C2957D2926
Now notice the dynamic proxy in exception message. After googling the issue, I found the following solution:
http://www.jonegerton.com/dotnet/aut...-a-workaround/
I did implement is but no luck. I googled more & found another solution:
public class LabEntities : DbContext
{
public LabEntities()
{
Configuration.ProxyCreationEnabled = false;
}
}
After doing this, the applications stops lazy loading. All child entities in parent entity becomes null, whenever I fetch data. This created another problem. I tried to solve in the below manner in my DAL:
public IEnumerable<RoutingRule> GetRoutingRuleList()
{_entities.Configuration.ProxyCreationEnabled = false;
var data = _entities.RoutingRules.OrderByDescending(r => r.Id).ToList();
_entities.Configuration.ProxyCreationEnabled = true;
return data;
}
Now initially it worked fine, but now it gives the old missing mapping error randomly, for the same screen and same data.
Can anyone kindly suggest what is the correct way of using AutoMapper with EntityFramework (Lazy Loading enabled).
Regards,
Shazia.