{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/945","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/945/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/945/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/945/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/945","id":112831802,"number":945,"title":"AutoMapper 4.1.0 Exception with Proxy on Inherited object with Entity Framework","user":{"login":"swilkos","id":1276720,"avatar_url":"https://avatars.githubusercontent.com/u/1276720?v=3","gravatar_id":"","url":"https://api.github.com/users/swilkos","html_url":"https://github.com/swilkos","followers_url":"https://api.github.com/users/swilkos/followers","following_url":"https://api.github.com/users/swilkos/following{/other_user}","gists_url":"https://api.github.com/users/swilkos/gists{/gist_id}","starred_url":"https://api.github.com/users/swilkos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/swilkos/subscriptions","organizations_url":"https://api.github.com/users/swilkos/orgs","repos_url":"https://api.github.com/users/swilkos/repos","events_url":"https://api.github.com/users/swilkos/events{/privacy}","received_events_url":"https://api.github.com/users/swilkos/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-10-22T15:41:31Z","updated_at":"2015-10-23T14:27:41Z","closed_at":"2015-10-23T14:04:49Z","body":"Seem to still have an issue with the latest build.  When creating an Entity Framework query and attempting to map the object over to a derived class causes a base object mapping exception.  Please let me know if more information is needed.\r\n\r\nClasses:\r\n```\r\n    public class ExampleContext : DbContext\r\n    {\r\n        public DbSet<TrainingCourse> TrainingCourses { get; set; }\r\n        public DbSet<TrainingContent> TrainingContents { get; set; }\r\n    }\r\n\r\n    public class TrainingCourse\r\n    {\r\n        public TrainingCourse()\r\n        {\r\n            Content = new List<TrainingContent>();\r\n        }\r\n\r\n        public TrainingCourse(TrainingCourse entity)\r\n        {\r\n\r\n            Mapper.Map(entity, this);\r\n        }\r\n\r\n        [Key]\r\n        public int CourseId { get; set; }\r\n\r\n        public string CourseName { get; set; }\r\n\r\n        public virtual ICollection<TrainingContent> Content { get; set; }\r\n    }\r\n\r\n    public class TrainingContent\r\n    {\r\n        public TrainingContent()\r\n        {\r\n        }\r\n\r\n        [Key]\r\n        public int ContentId { get; set; }\r\n\r\n        public string ContentName { get; set; }\r\n\r\n        public virtual TrainingCourse Course { get; set; }\r\n\r\n        public int CourseId { get; set; }\r\n\r\n    }\r\n\r\n    public class TrainingCourseDto\r\n    {\r\n        public int CourseId { get; set; }\r\n\r\n        public string CourseName { get; set; }\r\n\r\n        public ICollection<TrainingContentDto> Content { get; set; }\r\n    }\r\n\r\n    public class ParentTrainingCourseDto : TrainingCourseDto\r\n    {\r\n        [IgnoreMap]\r\n        public new ICollection<TrainingContentDto> Content { get; set; }\r\n    }\r\n\r\n    public class TrainingContentDto\r\n    {\r\n        public int ContentId { get; set; }\r\n\r\n        public string ContentName { get; set; }\r\n\r\n        public ParentTrainingCourseDto Course { get; set; }\r\n\r\n        public int CourseId { get; set; }\r\n    }\r\n```\r\n\r\nInitializer:\r\n```\r\n            Mapper.Initialize(\r\n                cfg =>\r\n                    {\r\n                        cfg.CreateMap<TrainingCourse, TrainingCourseDto>()\r\n                        .Include<TrainingCourse, ParentTrainingCourseDto>();\r\n                        cfg.CreateMap<TrainingCourse, ParentTrainingCourseDto>();\r\n                        cfg.CreateMap<TrainingContent, TrainingContentDto>();\r\n\r\n                        \r\n                    });\r\n\r\n            Mapper.Configuration.Seal();\r\n            Mapper.AssertConfigurationIsValid();\r\n```\r\n\r\nCode that throws an excption with Automapper 4.1.0\r\n```\r\n            ExampleContext context = new ExampleContext();\r\n            var course = context.TrainingCourses.FirstOrDefault(n => n.CourseName == \"Course 1\");\r\n            var dto = Mapper.Map<TrainingCourseDto>(course);\r\n```\r\n\r\nError thrown:\r\n```\r\nAutoMapper.AutoMapperMappingException : \r\n\r\nMapping types:\r\nTrainingCourse -> TrainingCourseDto\r\nAutoMapper.BugExample.TrainingCourse -> AutoMapper.BugExample.TrainingCourseDto\r\n\r\nDestination path:\r\nTrainingCourseDto.Content.Content.Content0[0].Course0[0].Course0[0]\r\n\r\nSource value:\r\nSystem.Data.Entity.DynamicProxies.TrainingCourse_1F4098BB48C8E550C9BD06AA4E5078C25E68A8F1D567EB1E395EAFE4C70847D6\r\n  ----> System.InvalidCastException : Unable to cast object of type 'AutoMapper.BugExample.TrainingCourseDto' to type 'AutoMapper.BugExample.ParentTrainingCourseDto'.\r\n```"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/150589768","html_url":"https://github.com/AutoMapper/AutoMapper/issues/945#issuecomment-150589768","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/945","id":150589768,"user":{"login":"jbogard","id":104498,"avatar_url":"https://avatars.githubusercontent.com/u/104498?v=3","gravatar_id":"","url":"https://api.github.com/users/jbogard","html_url":"https://github.com/jbogard","followers_url":"https://api.github.com/users/jbogard/followers","following_url":"https://api.github.com/users/jbogard/following{/other_user}","gists_url":"https://api.github.com/users/jbogard/gists{/gist_id}","starred_url":"https://api.github.com/users/jbogard/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jbogard/subscriptions","organizations_url":"https://api.github.com/users/jbogard/orgs","repos_url":"https://api.github.com/users/jbogard/repos","events_url":"https://api.github.com/users/jbogard/events{/privacy}","received_events_url":"https://api.github.com/users/jbogard/received_events","type":"User","site_admin":false},"created_at":"2015-10-23T14:27:41Z","updated_at":"2015-10-23T14:27:41Z","body":"What fix?"}}