{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1258","repository_url":"https://api.github.com/repos/AutoMapper/AutoMapper","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1258/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1258/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1258/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1258","id":153097205,"number":1258,"title":"ProjectTo<T> failing with dynamic properties on the target object","user":{"login":"crmckenzie","id":947569,"avatar_url":"https://avatars.githubusercontent.com/u/947569?v=3","gravatar_id":"","url":"https://api.github.com/users/crmckenzie","html_url":"https://github.com/crmckenzie","followers_url":"https://api.github.com/users/crmckenzie/followers","following_url":"https://api.github.com/users/crmckenzie/following{/other_user}","gists_url":"https://api.github.com/users/crmckenzie/gists{/gist_id}","starred_url":"https://api.github.com/users/crmckenzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crmckenzie/subscriptions","organizations_url":"https://api.github.com/users/crmckenzie/orgs","repos_url":"https://api.github.com/users/crmckenzie/repos","events_url":"https://api.github.com/users/crmckenzie/events{/privacy}","received_events_url":"https://api.github.com/users/crmckenzie/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-05-04T19:38:38Z","updated_at":"2016-05-05T15:39:44Z","closed_at":null,"body":"Given: \r\n\r\n        public class Widget\r\n        {\r\n            public int WidgetId { get; set; }\r\n        }\r\n\r\n        public class WidgetJson\r\n        {\r\n            public int WidgetId { get; set; }\r\n            public object Urls { get; set; }\r\n        }\r\n\r\n        public MapperConfiguration Config { get; set; }\r\n\r\n        [OneTimeSetUp]\r\n        public void BeforeAll()\r\n        {\r\n            this.Config = new MapperConfiguration(cfg =>\r\n            {\r\n                object Urls = null;\r\n                cfg.CreateMap<Widget, WidgetJson>()\r\n                    .ForMember(output => output.Urls, map => map.MapFrom(src => Urls));\r\n            });\r\n\r\n        }\r\n\r\n\r\n        [Test]\r\n        public void Widgets()\r\n        {\r\n            var widgets = Builder<Widget>\r\n                .CreateListOfSize(10)\r\n                .Build()\r\n                ;\r\n\r\n\r\n            var urls = new { Urls = new { Edit = \"edit\" } };\r\n            Expression<Func<WidgetJson, object>> map = config => urls;\r\n\r\n            var query = widgets.AsQueryable()\r\n                .ProjectTo<WidgetJson>(this.Config, urls)\r\n                ;\r\n\r\n            var results = query.ToList();\r\n\r\n            var result = query.First();\r\n            result.Urls.ShouldNotBe(null);\r\n        }\r\n\r\nThis test passes as written. However, if I change the type of Widget.Urls from object to dynamic:\r\n\r\n        public class WidgetJson\r\n        {\r\n            public int WidgetId { get; set; }\r\n            public dynamic Urls { get; set; }\r\n        }\r\n\r\nThe test will fail.\r\n\r\nFurther, if I try to use the Expression<Func<T, object>> parameter to ProjectTo<> instead of a constant value, the test will not pass regardless of the type of the Urls property.\r\n\r\n**Always Fails**\r\n\r\n        [Test]\r\n        public void Widgets()\r\n        {\r\n            var widgets = Builder<Widget>\r\n                .CreateListOfSize(10)\r\n                .Build()\r\n                ;\r\n\r\n\r\n            var urls = new { Urls = new { Edit = \"edit\" } };\r\n            Expression<Func<WidgetJson, object>> map = config => urls;\r\n\r\n            var query = widgets.AsQueryable()\r\n                .ProjectTo<WidgetJson>(this.Config, map)\r\n                ;\r\n\r\n            var results = query.ToList();\r\n\r\n            var result = query.First();\r\n            result.Urls.ShouldNotBe(null);\r\n        }\r\n\r\nIt's possible that I'm misusing the Expression in this case. I was unable to find any examples either in the documentation or in the code. Are there constraints on the Expression that are not visible?\r\n\r\nThe use-case I'm trying to satisfy is to create hypermedia links in json contracts from data retrieved over an odata api.\r\n\r\n**Sample Use Case**\r\n\r\n\tprivate object MapUrls(WidgetJson widget)\r\n\t{\r\n\t\tdynamic urls = new ExpandoObject();\r\n\r\n\t\turls.edit = Url.Link(\"Default\",\r\n\t\t\tnew { Controller = \"Widgets\", Action = \"Edit\", id = widget.Id });\r\n\t\turls.details = Url.Link(\"Default\",\r\n\t\t\tnew { Controller = \"Widgets\", Action = \"Details\", id = widget.Id });\r\n\r\n\t\treturn new { Urls = urls };\r\n\t}\r\n\r\nThoughts?"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/217189285","html_url":"https://github.com/AutoMapper/AutoMapper/issues/1258#issuecomment-217189285","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/1258","id":217189285,"user":{"login":"crmckenzie","id":947569,"avatar_url":"https://avatars.githubusercontent.com/u/947569?v=3","gravatar_id":"","url":"https://api.github.com/users/crmckenzie","html_url":"https://github.com/crmckenzie","followers_url":"https://api.github.com/users/crmckenzie/followers","following_url":"https://api.github.com/users/crmckenzie/following{/other_user}","gists_url":"https://api.github.com/users/crmckenzie/gists{/gist_id}","starred_url":"https://api.github.com/users/crmckenzie/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crmckenzie/subscriptions","organizations_url":"https://api.github.com/users/crmckenzie/orgs","repos_url":"https://api.github.com/users/crmckenzie/repos","events_url":"https://api.github.com/users/crmckenzie/events{/privacy}","received_events_url":"https://api.github.com/users/crmckenzie/received_events","type":"User","site_admin":false},"created_at":"2016-05-05T15:39:44Z","updated_at":"2016-05-05T15:39:44Z","body":"> The problem is with parameters most likely is when you pass Urls it's of type URL and not of type dynamic, so there's no way to link them together.\r\n\r\nThey're strings in my original code, but your point is well taken. That said, if the target property type is dynamic, I would expect the default behavior to be to simply assign the source property value to the target property. I have a workaround for my other issues, but I still think it would be nice if dynamic was supported in AutoMapper.\r\n\r\n"}}