{"record":{"id":"6d983ea3785931fc","repo":"dotnet/efcore","slug":"invalid-number-of-index-sort-order-values-numval","errorCode":null,"errorMessage":"Invalid number of index sort order values: {numValues} values were provided, but the index has {numProperties} properties.","messagePattern":"Invalid number of index sort order values: (.+?) values were provided, but the index has (.+?) properties\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Abstractions/IndexAttribute.cs","lineNumber":69,"sourceCode":"    public bool IsUnique\n    {\n        get => _isUnique ?? false;\n        set => _isUnique = value;\n    }\n\n    /// <summary>\n    ///     A set of values indicating whether each corresponding index column has descending sort order.\n    /// </summary>\n    public bool[]? IsDescending\n    {\n        get;\n        set\n        {\n            if (value is not null)\n            {\n                if (value.Length != PropertyNames.Count)\n                {\n                    throw new ArgumentException(\n                        AbstractionsStrings.InvalidNumberOfIndexSortOrderValues(value.Length, PropertyNames.Count), nameof(IsDescending));\n                }\n\n                if (AllDescending)\n                {\n                    throw new ArgumentException(AbstractionsStrings.CannotSpecifyBothIsDescendingAndAllDescending);\n                }\n            }\n\n            field = value;\n        }\n    }\n\n    /// <summary>\n    ///     Whether all index columns have descending sort order.\n    /// </summary>\n    public bool AllDescending\n    {","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Abstractions/IndexAttribute.cs#L51-L87","documentation":"The IndexAttribute.IsDescending property accepts a bool[] that specifies ascending/descending sort order per column. EF Core requires the array length to exactly match the number of property names passed to the [Index] attribute constructor. This mismatch check prevents ambiguous or incomplete sort-order declarations during model building.","triggerScenarios":"Setting [Index(\"MyIndex\", \"ColA\", \"ColB\")] and then assigning IsDescending = new[] { true } — the array has 1 element but the index declares 2 property names, so value.Length (1) != PropertyNames.Count (2).","commonSituations":"Adding or removing a column from a multi-column index without updating the IsDescending array; copy-pasting an [Index] attribute and changing property names but forgetting to update the sort-order array; refactoring a composite index.","solutions":["Ensure the IsDescending array length equals the number of property names passed to the [Index] constructor (1st positional arg + all params).","If all columns should descend, use the AllDescending property instead of IsDescending.","If you only need default ascending order, omit IsDescending entirely."],"exampleFix":"// before\n[Index(\"IX_Order\", \"CustomerId\", \"OrderDate\")]\npublic class Order { ... }\n// elsewhere: attribute.IsDescending = new[] { true }; // 1 value for 2 columns\n\n// after\n[Index(\"IX_Order\", \"CustomerId\", \"OrderDate\")]\npublic class Order { ... }\n// elsewhere: attribute.IsDescending = new[] { true, false }; // matches 2 columns","handlingStrategy":"validation","validationCode":"// Before assigning IsDescending, verify the array length matches the index property count\nvar attribute = new IndexAttribute(\"ColA\", \"ColB\");\nvar sortOrders = new[] { true, false };\nif (sortOrders.Length != attribute.PropertyNames.Count)\n{\n    throw new InvalidOperationException(\n        $\"IsDescending has {sortOrders.Length} values but index has {attribute.PropertyNames.Count} properties.\");\n}\nattribute.IsDescending = sortOrders;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When building IndexAttribute programmatically, derive the IsDescending array length from PropertyNames.Count.","Use AllDescending when all columns share the same sort direction.","Add a unit test that asserts IsDescending.Length == PropertyNames.Count for any programmatically built index."],"tags":["ef-core","index-attribute","model-validation","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}