Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4.5 > BOOK: Professional ASP.NET MVC 4
| Search | Today's Posts | Mark Forums Read
BOOK: Professional ASP.NET MVC 4
This is the forum to discuss the Wrox book Professional ASP.NET MVC 4 by Jon Galloway, Phil Haack, Brad Wilson, K. Scott Allen; ISBN: 978-1-118-34846-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional ASP.NET MVC 4 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 9th, 2015, 03:35 AM
Authorized User
Points: 200, Level: 3
Points: 200, Level: 3 Points: 200, Level: 3 Points: 200, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2005
Location: , , Pakistan.
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy AutoMapper exception while using MVC with EF

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.


Similar Threads
Thread Thread Starter Forum Replies Last Post
EF Repository hpcsc BOOK: Patterns, Principles and Practices of Domain-Driven Design 2 August 26th, 2015 03:26 AM
Scafolding for non-EF? RKevinBurton BOOK: Professional ASP.NET MVC 4 0 March 24th, 2015 09:21 AM
Chpt 4 -- MVC 5 EF Code First Database Generation JackHerr BOOK: Professional ASP.NET MVC 5 0 September 25th, 2014 03:54 PM
Errors while upgrade theBeerHouse mvc project form asp.net mvc 1.0 to 2.0 vanbach1304 BOOK: ASP.NET MVC Website Programming Problem Design Solution ISBN: 9780470410950 0 April 20th, 2010 06:43 AM
TheBeerHouse MVC preview ASP.NET MVC Website Programming Problem Design Solution jminatel BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 July 18th, 2009 09:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.