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
- Choose only one: either IsDescending for per-column control or AllDescending for uniform descending order.
- 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.
- 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
- Never set both AllDescending and IsDescending on the same IndexAttribute instance.
- Centralize index sort-order configuration in one location to avoid conflicting assignments.
- If merging configurations from multiple sources, check IsDescending for null before setting AllDescending.
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
- Invalid number of index sort order values
- 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/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)