{"record":{"id":"257e1a05f2bfc495","repo":"dotnet/efcore","slug":"invalid-type-for-sequence-valid-types-are-long","errorCode":null,"errorMessage":"Invalid type for sequence. Valid types are 'long' (the default), 'int', 'short', 'byte' and 'decimal'.","messagePattern":"Invalid type for sequence\\. Valid types are 'long' \\(the default\\), 'int', 'short', 'byte' and 'decimal'\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/Sequence.cs","lineNumber":509,"sourceCode":"    {\n        get => _type ?? DefaultClrType;\n        set => SetType(value, ConfigurationSource.Explicit);\n    }\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 virtual Type? SetType(Type? type, ConfigurationSource configurationSource)\n    {\n        EnsureMutable();\n\n        if (type != null\n            && !SupportedTypes.Contains(type))\n        {\n            throw new ArgumentException(RelationalStrings.BadSequenceType);\n        }\n\n        _type = type;\n\n        _typeConfigurationSource = type == null\n            ? null\n            : configurationSource.Max(_typeConfigurationSource);\n\n        return type;\n    }\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 virtual ConfigurationSource? GetTypeConfigurationSource()","sourceCodeStart":491,"sourceCodeEnd":527,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/Sequence.cs#L491-L527","documentation":"Thrown when SetType is called on a Sequence with a CLR type not in the supported set. EF Core sequences are database counters and only the integer/decimal families are valid backing types.","triggerScenarios":"Sequence.SetType(type, configurationSource) when type is non-null and not in SupportedTypes (byte, short, int, long, decimal). Triggered by HasSequence<SomeType>() or sequence.HasType(typeof(...)) with an unsupported type such as Guid, string, DateTime, or float.","commonSituations":"Calling HasSequence<Guid>() by mistake; passing a float/double wanting fractional increments; copying a generic argument from the column type into the sequence; using a custom value type.","solutions":["Use one of the supported types: long (default), int, short, byte, or decimal.","Switch to long unless a narrower integer range is required.","If decimal precision is needed, use decimal and verify the provider supports decimal sequences (not all do)."],"exampleFix":"// before\nmodelBuilder.HasSequence<Guid>(\"MySeq\"); // throws\n\n// after\nmodelBuilder.HasSequence<long>(\"MySeq\");","handlingStrategy":"type-guard","validationCode":"// Validate the type before assigning it to a sequence.\nvar supported = new[] { typeof(long), typeof(int), typeof(short), typeof(byte), typeof(decimal) };\nif (!supported.Contains(requestedType))\n    throw new ArgumentOutOfRangeException(nameof(requestedType),\n        \"Sequence type must be one of: long, int, short, byte, decimal.\");\nmodelBuilder.HasSequence(requestedType, \"OrderSeq\");","typeGuard":"static bool IsValidSequenceType(Type t)\n    => t == typeof(long) || t == typeof(int) || t == typeof(short)\n       || t == typeof(byte) || t == typeof(decimal);","tryCatchPattern":null,"preventionTips":["Restrict HasSequence<T> to the supported numeric types only.","Default to long unless a narrower type is required.","Add a unit test that asserts every HasSequence call uses a supported type."],"tags":["ef-core","relational-metadata","sequence","type-validation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}