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.
RoutingRule -> RoutingViewModel
Iris.Models.Configuration.RoutingRule -> Iris.Web.Configuration.ViewModels.RoutingViewModel
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:
I did implement is but no luck. I googled more & found another solution:
public class LabEntities : DbContext
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;
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).