{"record":{"id":"88b4504d9b94da7c","repo":"dotnet/efcore","slug":"numsortorderproperties-values-were-provided-in-c","errorCode":null,"errorMessage":"{numSortOrderProperties} values were provided in CreateIndexOperations.IsDescending, but the operation has {numColumns} columns.","messagePattern":"(.+?) values were provided in CreateIndexOperations\\.IsDescending, but the operation has (.+?) columns\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs","lineNumber":43,"sourceCode":"    /// </summary>\n    public virtual string? Schema { get; set; }\n\n    /// <summary>\n    ///     The table that contains the index.\n    /// </summary>\n    public virtual string Table { get; set; } = null!;\n\n    /// <summary>\n    ///     The ordered list of column names for the column that make up the index.\n    /// </summary>\n    public virtual string[] Columns\n    {\n        get => _columns!;\n        set\n        {\n            if (_isDescending is not null && _isDescending.Length > 0 && value.Length != _isDescending.Length)\n            {\n                throw new ArgumentException(RelationalStrings.CreateIndexOperationWithInvalidSortOrder(_isDescending.Length, value.Length));\n            }\n\n            _columns = value;\n        }\n    }\n\n    /// <summary>\n    ///     Indicates whether or not the index should enforce uniqueness.\n    /// </summary>\n    public virtual bool IsUnique { get; set; }\n\n    /// <summary>\n    ///     A set of values indicating whether each corresponding index column has descending sort order.\n    /// </summary>\n    public virtual bool[]? IsDescending\n    {\n        get => _isDescending;\n        set","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Migrations/Operations/CreateIndexOperation.cs#L25-L61","documentation":"Thrown by the CreateIndexOperation.Columns setter when assigning a new columns array whose length does not match the already-set IsDescending array length. The two arrays must be element-aligned (one sort-order flag per column), so EF rejects any mismatch as an ArgumentException at assignment time.","triggerScenarios":"Setting operation.Columns after operation.IsDescending with arrays of different lengths; creating a CreateIndexOperation where IsDescending was assigned first and Columns is later set to a differently-sized array.","commonSituations":"Hand-building a CreateIndexOperation in code/migrations with mismatched array sizes; copying an index operation and editing only one of the two arrays; provider/annotation code that mutates Columns after IsDescending is populated.","solutions":["Ensure the Columns array and the IsDescending array have identical lengths when setting Columns after IsDescending.","Set IsDescending to null before changing the column count, then assign the correctly-sized IsDescending array afterwards.","Construct both arrays together from the same source (e.g. project from the index's columns) so they cannot drift."],"exampleFix":"// before\nvar op = new CreateIndexOperation\n{\n    Name = \"IX\",\n    Table = \"T\",\n    IsDescending = new[] { true, false }\n};\nop.Columns = new[] { \"A\" }; // length mismatch -> throws\n\n// after\nop.Columns = new[] { \"A\", \"B\" }; // matches IsDescending length","handlingStrategy":"validation","validationCode":"static CreateIndexOperation BuildIndex(string table, string[] cols, bool[]? desc)\n{\n    if (desc is { Length: > 0 } && desc.Length != cols.Length)\n        throw new ArgumentException($\"IsDescending length {desc.Length} != columns {cols.Length}\");\n    return new CreateIndexOperation { Name = \"IX_\" + table, Table = table, Columns = cols, IsDescending = desc };\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build Columns and IsDescending from the same source list so they cannot diverge.","Set IsDescending to null when changing column count, then assign the matching array."],"tags":["efcore","migrations","index","validation","argument"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}