{"action":"created","issue":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/889","labels_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/889/labels{/name}","comments_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/889/comments","events_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/889/events","html_url":"https://github.com/AutoMapper/AutoMapper/issues/889","id":106419432,"number":889,"title":"Mapping Queryable Expressions fails when using variable","user":{"login":"simoco","id":8275275,"avatar_url":"https://avatars.githubusercontent.com/u/8275275?v=3","gravatar_id":"","url":"https://api.github.com/users/simoco","html_url":"https://github.com/simoco","followers_url":"https://api.github.com/users/simoco/followers","following_url":"https://api.github.com/users/simoco/following{/other_user}","gists_url":"https://api.github.com/users/simoco/gists{/gist_id}","starred_url":"https://api.github.com/users/simoco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simoco/subscriptions","organizations_url":"https://api.github.com/users/simoco/orgs","repos_url":"https://api.github.com/users/simoco/repos","events_url":"https://api.github.com/users/simoco/events{/privacy}","received_events_url":"https://api.github.com/users/simoco/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-14T20:18:02Z","updated_at":"2015-09-15T05:35:20Z","closed_at":null,"body":"Please, advice on how to fix this issue. This one works:\r\n\r\n    Expression<Func<IQueryable<Dto>, IQueryable<Dto>>> expr = dtos => dtos.Where(dto => dto.A == \"Test\" && dto.Type == 1);\r\n    var mappedExpr = Mapper.Map<Expression<Func<IQueryable<Model>, IQueryable<Model>>>>(expr);\r\n\r\nwhile this one doesn't:\r\n\r\n    Expression<Func<Dto,bool>> exprInVariable = dto => dto.A == \"Test\" && dto.Type == 1;\r\n    Expression<Func<IQueryable<Dto>, IQueryable<Dto>>> expr = dtos => dtos.Where(exprInVariable);\r\n    var mappedExpr = Mapper.Map<Expression<Func<IQueryable<Model>, IQueryable<Model>>>>(expr);\r\n\r\nThe only change is that I store expression in variable. It fails with exception:\r\n\r\n>AutoMapper.AutoMapperMappingException: \r\n>Mapping types:\r\n>Expression`1 -> Expression`1\r\n>\r\n>System.Linq.Expressions.Expression`1[[System.Func`2[[System.Linq.IQueryable`1[[Tests.Fake.Dto, Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Linq.IQueryable`1[[Tests.Fake.Dto, Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] -> System.Linq.Expressions.Expression`1[[System.Func`2[[System.Linq.IQueryable`1[[Tests.Fake.Model, Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Linq.IQueryable`1[[Tests.Fake.Model, Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]], System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\r\n>\r\n>Destination path:\r\n>\r\n>Expression`1\r\n>Source value:\r\n>dtos => >dtos.Where(value(Tests.Infrastructure.Mappers.ExpressionAutoMapperTests+<>c__DisplayClass21).exprInVariable) ---> System.ArgumentException: Expression of type 'System.Linq.Expressions.Expression`1[System.Func`2[Tests.Fake.Dto,System.Boolean]]' cannot be used for parameter of type 'System.Linq.Expressions.Expression`1[System.Func`2[Tests.Fake.Model,System.Boolean]]' of method 'System.Linq.IQueryable`1[Tests.Fake.Model] Where[Model](System.Linq.IQueryable`1[Tests.Fake.Model], System.Linq.Expressions.Expression`1[System.Func`2[Tests.Fake.Model,System.Boolean]])'\r\n    at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)\r\n   at System.Linq.Expressions.Expression.ValidateArgumentTypes(MethodBase method, ExpressionType nodeKind, ref ReadOnlyCollection`1 arguments)\r\n   at System.Linq.Expressions.Expression.Call(Expression instance, MethodInfo method, IEnumerable`1 arguments)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.GetConvertedMethodCall(MethodCallExpression node)\r\n   at AutoMapper.Mappers.ExpressionMapper.MappingVisitor.VisitMethodCall(MethodCallExpression node)\r\n   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)\r\n   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)\r\n   at AutoMapper.Mappers.ExpressionMapper.Map(ResolutionContext context, IMappingEngineRunner mapper)\r\n   at AutoMapper.MappingEngine.AutoMapper.IMappingEngineRunner.Map(ResolutionContext context)\r\n --- End of inner exception stack trace ---\r\n\r\nMy mappings are registered as follows:\r\n\r\n    Mapper.CreateMap<Model, Dto>()\r\n                .ForMember(dst => dst.A, opt => opt.MapFrom(src => src.Name))\r\n                .ForMember(dst => dst.B, opt => opt.MapFrom(src => src.Foo.Name));\r\n\r\n    Mapper.CreateMap<Dto, Model>()\r\n                .ForMember(dst => dst.Name, opt => opt.MapFrom(src => src.A))\r\n                .ForMember(dst => dst.Foo, opt => opt.MapFrom(src => new SubModel {Id = src.Id, Name = src.B}));\r\n\r\nMy model and dto classes are looks like:\r\n\r\n    public class Model \r\n    {\r\n        public Guid Id { get; set; }\r\n        public string Name { get; set; }\r\n        public int Type { get; set; }\r\n        public SubModel Foo { get; set; }\r\n    }\r\n    \r\n    public class SubModel\r\n    {\r\n        public Guid Id { get; set; }\r\n        public string Name { get; set; } \r\n    }\r\n\r\n    public class Dto \r\n    {\r\n        public Guid Id { get; set; }\r\n        public string A { get; set; }\r\n        public string B { get; set; }\r\n        public int Type { get; set; }\r\n    }\r\n\r\nSo, how can I use Queryable Expression mapping with expression in variable?\r\n"},"comment":{"url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/comments/140286775","html_url":"https://github.com/AutoMapper/AutoMapper/issues/889#issuecomment-140286775","issue_url":"https://api.github.com/repos/AutoMapper/AutoMapper/issues/889","id":140286775,"user":{"login":"simoco","id":8275275,"avatar_url":"https://avatars.githubusercontent.com/u/8275275?v=3","gravatar_id":"","url":"https://api.github.com/users/simoco","html_url":"https://github.com/simoco","followers_url":"https://api.github.com/users/simoco/followers","following_url":"https://api.github.com/users/simoco/following{/other_user}","gists_url":"https://api.github.com/users/simoco/gists{/gist_id}","starred_url":"https://api.github.com/users/simoco/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/simoco/subscriptions","organizations_url":"https://api.github.com/users/simoco/orgs","repos_url":"https://api.github.com/users/simoco/repos","events_url":"https://api.github.com/users/simoco/events{/privacy}","received_events_url":"https://api.github.com/users/simoco/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T05:35:20Z","updated_at":"2015-09-15T05:35:20Z","body":"Hi @TylerCarlson1 , I'm trying to create expression that transforms `IQueryable<Dto>` to  `IQueryable<Dto>` and after that map it to the expression that transforms `IQueryable<Model>` to  `IQueryable<Model>`. The thing is very similar to [the example described on your wiki page](https://github.com/AutoMapper/AutoMapper/wiki/Expression-Translation-(UseAsDataSource)). I know in this very simplified example I can directly map `Expression<Func<Dto,bool>>` to `Expression<Func<Model,bool>>` and use it, but in my real code I need to map `Expression<Func<IQueryable<Dto>, IQueryable<Dto>>>` to `Expression<Func<IQueryable<Model>, IQueryable<Model>>>`. So, do you have any ideas why it's not working when storing expression `Expression<Func<Dto,bool>>` in variable?"}}