{"record":{"id":"2ddececa73d49aef","repo":"LuckyPennySoftware/AutoMapper","slug":"error-building-queryable-mapping-strategy","errorCode":null,"errorMessage":"Error building queryable mapping strategy.","messagePattern":"Error building queryable mapping strategy\\.","errorType":"exception","errorClass":"AutoMapperMappingException","httpStatus":null,"severity":"error","filePath":"src/AutoMapper/QueryableExtensions/ProjectionBuilder.cs","lineNumber":131,"sourceCode":"            {\n                foreach (var propertyMap in typeMap.PropertyMaps)\n                {\n                    if (!propertyMap.CanResolveValue || !propertyMap.CanBeSet || typeMap.ConstructorParameterMatches(propertyMap.DestinationName))\n                    {\n                        continue;\n                    }\n\n                    try\n                    {\n                        var propertyProjection = TryProjectMember(propertyMap);\n                        if (propertyProjection != null)\n                        {\n                            propertiesProjections.Add(Bind(propertyMap.DestinationMember, propertyProjection));\n                        }\n                    }\n                    catch (Exception e) when (e is not AutoMapperConfigurationException)\n                    {\n                        throw new AutoMapperMappingException(\"Error building queryable mapping strategy.\", e, propertyMap);\n                    }\n                }\n            }\n            Expression TryProjectMember(MemberMap memberMap, Expression defaultSource = null)\n            {\n                MemberProjection memberProjection = new(memberMap);\n                letPropertyMaps.Push(memberProjection);\n                var memberExpression = ShouldExpand() ? ProjectMemberCore() : null;\n                letPropertyMaps.Pop();\n                return memberExpression;\n                bool ShouldExpand() => memberMap.ExplicitExpansion != true || request.ShouldExpand(letPropertyMaps.GetCurrentPath());\n                Expression ProjectMemberCore()\n                {\n                    var memberTypeMap = _configuration.ResolveTypeMap(memberMap.SourceType, memberMap.DestinationType);\n                    var resolvedSource = ResolveSource();\n                    memberProjection.Expression ??= resolvedSource;\n                    var memberRequest = request.InnerRequest(resolvedSource.Type, memberMap.DestinationType);\n                    if (memberRequest.AlreadyExists && depth >= _configuration.RecursiveQueriesMaxDepth)","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/LuckyPennySoftware/AutoMapper/blob/dfa6dd587c5854b4beee5934beb39ba6e9569b84/src/AutoMapper/QueryableExtensions/ProjectionBuilder.cs#L113-L149","documentation":"ProjectionBuilder translates a type map into a LINQ expression for ProjectTo (EF/IQueryable). For each destination property it calls TryProjectMember; any exception other than AutoMapperConfigurationException is wrapped in AutoMapperMappingException carrying the failing propertyMap and the original exception as InnerException. So the message names the surface, while InnerException is the real cause.","triggerScenarios":"ProjectTo<Dest>(query) where a member's projection expression cannot be translated by the EF/LINQ provider: a MapFrom calling an unsupported method, a null reference inside the expression, a nested type with no map, or logic that is valid in-memory but not in the store.","commonSituations":"MapFrom lambdas invoking custom/static methods, .ToString() on providers that reject it, complex conditional logic, date/enum formatting, EF version/provider differences, or a missing CreateProjection for a referenced child type.","solutions":["Read ex.InnerException plus the failing member (ex.Types / the propertyMap in the exception) to find which projection broke and why.","Simplify the offending member's MapFrom to an expression the EF provider can translate, or remove server-side formatting.","Project the raw column server-side and compute the derived value in-memory after ProjectTo returns.","Ensure every nested type used in the projection has its own CreateMap/CreateProjection."],"exampleFix":"// before\nCreateMap<Order, OrderDto>().ForCtorParam// or\nCreateMap<Order, OrderDto>().ForMember(d => d.Total, o => o.MapFrom(s => s.Lines.CalculateTotal())); // untranslatable method\nvar dtos = ctx.Orders.ProjectTo<OrderDto>(_cfg).ToList(); // throws\n\n// after\nCreateMap<Order, OrderDto>().ForMember(d => d.Total, o => o.MapFrom(s => s.Lines.Sum(l => l.Price * l.Qty))); // translatable\nvar dtos = ctx.Orders.ProjectTo<OrderDto>(_cfg).ToList();","handlingStrategy":"try-catch","validationCode":"// Validate at startup that projections build against the provider:\nconfiguration.AssertConfigurationIsValid();\n// For runtime guards, keep a known-translatable expression set and a unit test\n// that runs ProjectTo against an in-memory IQueryable to confirm translation.","typeGuard":null,"tryCatchPattern":"try\n{\n    result = query.ProjectTo<Dest>(_cfg).ToList();\n}\ncatch (AutoMapperMappingException ex) when (ex.Message.Contains(\"queryable mapping strategy\"))\n{\n    var root = ex.InnerException;\n    var failingMember = ex.MemberMap?.DestinationName;\n    // log root + failingMember, then simplify that member's MapFrom and retry\n}","preventionTips":["Keep ProjectTo MapFrom lambdas free of custom methods; prefer arithmetic/string/linq the provider translates.","Add an integration test that runs ProjectTo against the real provider, not just AssertConfigurationIsValid.","When a value needs in-memory formatting, project the raw field and format after enumeration."],"tags":["projection","entity-framework","linq","queryable","projectto"],"backgroundTag":null,"analyzedSha":"dfa6dd587c5854b4beee5934beb39ba6e9569b84","analyzedAt":"2026-08-13T19:56:33.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}