{"record":{"id":"8df1b7c4a1a2abcc","repo":"dotnet/efcore","slug":"unsupported-numeric-type-mapping-type","errorCode":null,"errorMessage":"Unsupported numeric type mapping: '{type}'.","messagePattern":"Unsupported numeric type mapping: '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Storage/Internal/CosmosNumberProjectionTypeMapping.cs","lineNumber":32,"sourceCode":"public static class CosmosNumberProjectionTypeMapping\n{\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public static CosmosTypeMapping CreateFromType(Type type)\n        => type == typeof(int) ? CosmosNumberProjectionTypeMapping<int>.Default\n            : type == typeof(long) ? CosmosNumberProjectionTypeMapping<long>.Default\n            : type == typeof(short) ? CosmosNumberProjectionTypeMapping<short>.Default\n            : type == typeof(sbyte) ? CosmosNumberProjectionTypeMapping<sbyte>.Default\n            : type == typeof(float) ? CosmosNumberProjectionTypeMapping<float>.Default\n            : type == typeof(uint) ? CosmosNumberProjectionTypeMapping<uint>.Default\n            : type == typeof(ulong) ? CosmosNumberProjectionTypeMapping<ulong>.Default\n            : type == typeof(ushort) ? CosmosNumberProjectionTypeMapping<ushort>.Default\n            : type == typeof(byte) ? CosmosNumberProjectionTypeMapping<byte>.Default\n            : throw new InvalidOperationException($\"Unsupported numeric type mapping: '{type}'.\");\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public static bool IsRequiredForType(Type type)\n        => type == typeof(int)\n            || type == typeof(long)\n            || type == typeof(short)\n            || type == typeof(sbyte)\n            || type == typeof(float)\n            || type == typeof(uint)\n            || type == typeof(ulong)\n            || type == typeof(ushort)\n            || type == typeof(byte);\n}","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Storage/Internal/CosmosNumberProjectionTypeMapping.cs#L14-L50","documentation":"CosmosNumberProjectionTypeMapping.CreateFromType is a factory mapping CLR numeric types to specialized CosmosNumberProjectionTypeMapping<T> instances. It supports int, long, short, sbyte, float, uint, ulong, ushort, byte. Any other Type throws InvalidOperationException with an interpolated message listing the unsupported type. This is internal-API misuse: the model pipeline handed in a numeric type the provider does not handle.","triggerScenarios":"Internal code (or a custom type mapping) calls CreateFromType with an unsupported numeric CLR type such as double, decimal, or char. Most commonly reached when a property of type double/decimal is configured for Cosmos projection.","commonSituations":"Mapping a decimal or double property in a way that routes through the numeric projection path. Custom value converters or type mappings that surface an unsupported numeric type. Provider bug after a model change.","solutions":["Map decimal/double properties with a value converter to a supported numeric type (e.g. long or int), or store them as strings.","If you reached this via reflection/internal API, pass only one of the supported types (int, long, short, sbyte, float, uint, ulong, ushort, byte).","File an issue / use a different mapping strategy if a genuine double projection is required."],"exampleFix":"// before\nmodelBuilder.Entity<Sample>().Property(s => s.Amount).HasColumnType(\"decimal\");\n// internal pipeline calls CreateFromType(typeof(decimal)) -> throws\n\n// after - convert to a supported numeric type\nmodelBuilder.Entity<Sample>()\n    .Property(s => s.Amount)\n    .HasConversion(v => (long)(v * 100), v => (decimal)v / 100m);","handlingStrategy":"validation","validationCode":"static readonly HashSet<Type> Supported = new()\n{ typeof(int), typeof(long), typeof(short), typeof(sbyte),\n  typeof(float), typeof(uint), typeof(ulong), typeof(ushort), typeof(byte) };\n\nforeach (var prop in dbContext.Model.GetEntityTypes().SelectMany(t => t.GetProperties()))\n{\n    var clr = prop.ClrType.UnwrapNullable();\n    if (!Supported.Contains(clr) && clr.IsNumeric())\n        throw new InvalidOperationException($\"{prop.Name} maps unsupported numeric {clr}.\");\n}","typeGuard":"static bool IsSupportedCosmosNumeric(Type t)\n    => t == typeof(int) || t == typeof(long) || t == typeof(short) || t == typeof(sbyte)\n       || t == typeof(float) || t == typeof(uint) || t == typeof(ulong)\n       || t == typeof(ushort) || t == typeof(byte);","tryCatchPattern":null,"preventionTips":["Convert decimal/double to a supported numeric type via HasConversion.","Avoid passing unsupported numeric types to internal Cosmos type-mapping APIs.","Add a model-validation test for unsupported numeric properties."],"tags":["cosmos","type-mapping","numeric","internal-api","decimal"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}