{"record":{"id":"88451cca301725b7","repo":"dotnet/efcore","slug":"the-expression-sqlexpression-in-the-sql-tree-d","errorCode":null,"errorMessage":"The expression '{sqlExpression}' in the SQL tree does not have a type mapping assigned.","messagePattern":"The expression '(.+?)' in the SQL tree does not have a type mapping assigned\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs","lineNumber":1199,"sourceCode":"    //     public IEntityType EntityType { get; }\n    //\n    //     public override Type Type { get; }\n    //\n    //     public override ExpressionType NodeType\n    //         => ExpressionType.Extension;\n    //\n    //     public Expression Convert(Type type)\n    //         => type == typeof(object) // Ignore object conversion\n    //             || type.IsAssignableFrom(Type) // Ignore conversion to base/interface\n    //                 ? this\n    //                 : new EntityReferenceExpression(ParameterEntity, type);\n    // }\n\n    private sealed class SqlTypeMappingVerifyingExpressionVisitor : ExpressionVisitor\n    {\n        protected override Expression VisitExtension(Expression extensionExpression)\n            => extensionExpression is SqlExpression { TypeMapping: null } sqlExpression\n                ? throw new InvalidOperationException(CosmosStrings.NullTypeMappingInSqlTree(sqlExpression.Print()))\n                : base.VisitExtension(extensionExpression);\n    }\n}\n","sourceCodeStart":1181,"sourceCodeEnd":1203,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosSqlTranslatingExpressionVisitor.cs#L1181-L1203","documentation":"Thrown by an internal SqlTypeMappingVerifyingExpressionVisitor that walks the translated Cosmos SQL tree and asserts every SqlExpression has a CoreTypeMapping assigned. A null TypeMapping means the provider produced a SQL fragment for a CLR type it cannot serialize to/from Cosmos JSON. This signals either an unsupported CLR type in the query or a bug in the Cosmos query translator.","triggerScenarios":"A LINQ query references a property whose CLR type has no Cosmos type mapping (custom struct, unmapped 3rd-party type, or a value converter yielding an unmappable storage type). The verifier runs at the end of CosmosSqlTranslatingExpressionVisitor translation and fails on the offending expression (printed in the message).","commonSituations":"Using owned/complex types with unusual CLR property types; custom value converters that convert to a type Cosmos doesn't recognize; querying a property added without configuration after an EF Core upgrade that changed type-mapping resolution.","solutions":["Read the expression printed in the message to find which property/expression lacks a mapping.","Ensure the property's CLR type is one Cosmos supports (primitives, string, Guid, DateTime, TimeSpan, enums, etc.) or configure a value converter to a supported storage type via HasConversion<string>() / HasConversion<T>.","If the type should be supported, check for a missing Cosmos type mapping source registration and report a provider bug if mapping resolution legitimately returns null.","As a workaround, project/compute the value client-side so it is excluded from the server-translated tree."],"exampleFix":"// before: ulong property with no Cosmos mapping\nmodelBuilder.Entity<Order>().Property(o => o.Flags);\nvar q = ctx.Orders.Where(o => o.Flags > 0);\n\n// after: convert to a Cosmos-mapped primitive\nmodelBuilder.Entity<Order>()\n    .Property(o => o.Flags)\n    .HasConversion<long>();","handlingStrategy":"validation","validationCode":"// Verify each property on the queried entity has a Cosmos type mapping before running the query.\nforeach (var prop in typeof(Order).GetProperties())\n{\n    var mapping = cosmosModel.FindEntityType(typeof(Order))\n        ?.FindProperty(prop.Name)?.GetTypeMapping();\n    if (mapping is null)\n        Console.WriteLine($\"No Cosmos mapping for {prop.Name} ({prop.PropertyType}); add HasConversion.\");\n}","typeGuard":"// Narrow to properties known to have a mapping before projecting them.\nstatic bool HasCosmosMapping(IProperty p) => p.GetTypeMapping() is not null;","tryCatchPattern":"try { var results = query.ToList(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"does not have a type mapping\"))\n{\n    // log the offending expression, fall back to client evaluation\n}","preventionTips":["Configure value converters (HasConversion) for any non-primitive property before writing queries against it.","Add an integration test that materializes each entity to catch unmapped types at build time.","Keep the model's property type mappings explicit rather than relying on convention."],"tags":["cosmos","query-translation","type-mapping","sql-tree"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}