{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Abstractions/IndexAttribute.cs#L51-L87","documentation":"Thrown by the IndexAttribute.IsDescending setter when the supplied bool[] length does not equal PropertyNames.Count. The index needs exactly one sort-direction flag per property so each column's order is unambiguous; any mismatch is a modeling configuration error. It surfaces during model building when EF Core (or your own code) processes the attribute.","triggerScenarios":"Setting indexAttr.IsDescending to an array whose Length != the number of property names passed to the IndexAttribute constructor. For example, constructing new IndexAttribute(\"A\", \"B\") then assigning IsDescending = new[] { true } (1 flag for a 2-property index).","commonSituations":"Adding a descending flag to a composite index but forgetting to provide a flag for every column. Refactoring an index from single to composite property and forgetting to extend the IsDescending array. Migrating code from AllDescending to per-column IsDescending.","solutions":["Make the IsDescending array length equal to the number of properties in the index: one bool per property, in the same order.","If you want all columns descending, set AllDescending = true instead of IsDescending.","Double-check the property names list passed to the IndexAttribute constructor and align the IsDescending entries to it."],"exampleFix":"// before\nvar idx = new IndexAttribute(\"FirstName\", \"LastName\") { IsDescending = new[] { true } };\n\n// after\nvar idx = new IndexAttribute(\"FirstName\", \"LastName\") { IsDescending = new[] { true, false } };\n// or, all descending:\nvar idx2 = new IndexAttribute(\"FirstName\", \"LastName\") { AllDescending = true };","handlingStrategy":"validation","validationCode":"// Before assigning IsDescending, ensure one flag per property\nif (isDescendingArray != null && isDescendingArray.Length != indexAttr.PropertyNames.Count)\n{\n    throw new InvalidOperationException(\n        $\"Expected {indexAttr.PropertyNames.Count} sort flags, got {isDescendingArray.Length}.\");\n}\nindexAttr.IsDescending = isDescendingArray;","typeGuard":"static bool IsValidIsDescending(IndexAttribute attr, bool[]? flags)\n    => flags is null || flags.Length == attr.PropertyNames.Count;","tryCatchPattern":null,"preventionTips":["Always size the IsDescending array to match the number of properties passed to the IndexAttribute constructor.","Prefer AllDescending when every column should descend, to avoid array-length bookkeeping.","Centralize index attribute construction in a helper that validates flag count."],"tags":["ef-core","modeling","index","configuration","argument-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}