dotnet/efcore · error · ArgumentException
Invalid number of index sort order values
Error message
Invalid number of index sort order values: {numValues} values were provided, but the index has {numProperties} properties. What it means
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.
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.
Example fix
// before
[Index("IX_Order", "CustomerId", "OrderDate")]
public class Order { ... }
// elsewhere: attribute.IsDescending = new[] { true }; // 1 value for 2 columns
// after
[Index("IX_Order", "CustomerId", "OrderDate")]
public class Order { ... }
// elsewhere: attribute.IsDescending = new[] { true, false }; // matches 2 columns Defensive patterns
Strategy: validation
Validate before calling
// Before assigning IsDescending, verify the array length matches the index property count
var attribute = new IndexAttribute("ColA", "ColB");
var sortOrders = new[] { true, false };
if (sortOrders.Length != attribute.PropertyNames.Count)
{
throw new InvalidOperationException(
$"IsDescending has {sortOrders.Length} values but index has {attribute.PropertyNames.Count} properties.");
}
attribute.IsDescending = sortOrders; Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- IsDescending and AllDescending cannot both be specified on…
- The mapping strategy
- The number argument cannot be a negative number.
- The property ' ' on type ' ' cannot be configured as not…
- A full-text index is defined for
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/6d983ea3785931fc.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Abstractions/IndexAttribute.cs:69
public bool IsUnique
{
get => _isUnique ?? false;
set => _isUnique = value;
}
/// <summary>
/// A set of values indicating whether each corresponding index column has descending sort order.
/// </summary>
public bool[]? IsDescending
{
get;
set
{
if (value is not null)
{
if (value.Length != PropertyNames.Count)
{
throw new ArgumentException(
AbstractionsStrings.InvalidNumberOfIndexSortOrderValues(value.Length, PropertyNames.Count), nameof(IsDescending));
}
if (AllDescending)
{
throw new ArgumentException(AbstractionsStrings.CannotSpecifyBothIsDescendingAndAllDescending);
}
}
field = value;
}
}
/// <summary>
/// Whether all index columns have descending sort order.
/// </summary>
public bool AllDescending
{View on GitHub (pinned to 3a2006ef56)