dotnet/efcore · error · ArgumentException

IsDescending and AllDescending cannot both be specified on…

Error message

IsDescending and AllDescending cannot both be specified on the [Index] attribute.

What it means

The IndexAttribute enforces mutual exclusivity between IsDescending (per-column array) and AllDescending (single boolean). The IsDescending setter checks whether AllDescending has already been set to true and rejects the assignment. This prevents conflicting sort-order specifications on the same index.

Solutions

  1. Choose only one: either IsDescending for per-column control or AllDescending for uniform descending order.
  2. If you previously set AllDescending, clear it before setting IsDescending (or vice versa) — though IndexAttribute does not support unsetting, so decide upfront which property to use.
  3. Review all configuration sources (attributes, fluent API, conventions) that touch the same index to ensure they agree on sort-order strategy.

Example fix

// before
var attr = new IndexAttribute("ColA", "ColB");
attr.AllDescending = true;
attr.IsDescending = new[] { true, false }; // throws

// after
var attr = new IndexAttribute("ColA", "ColB");
attr.IsDescending = new[] { true, false }; // per-column control only
Defensive patterns

Strategy: validation

Validate before calling

// Track which sort-order property has been set before assigning
var attribute = new IndexAttribute("ColA", "ColB");
// Decide upfront: use per-column or uniform
if (wantUniformDescending)
{
    attribute.AllDescending = true;
}
else
{
    attribute.IsDescending = new[] { true, false };
}

Prevention

When it happens

Trigger: Setting attribute.AllDescending = true first, then subsequently setting attribute.IsDescending = new[] { true, false } — the IsDescending setter detects AllDescending is true and throws.

Common situations: Building an IndexAttribute programmatically where code sets AllDescending earlier in a fluent/programmatic configuration flow, then later code (perhaps from a different convention or configuration source) tries to set IsDescending; merging index configurations from multiple sources.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/583207320a60c2a4. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Abstractions/IndexAttribute.cs:75

    /// <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
    {
        get;
        set
        {
            if (IsDescending is not null)
            {
                throw new ArgumentException(AbstractionsStrings.CannotSpecifyBothIsDescendingAndAllDescending);

View on GitHub (pinned to 3a2006ef56)