{"record":{"id":"583207320a60c2a4","repo":"dotnet/efcore","slug":"isdescending-and-alldescending-cannot-both-be-spec","errorCode":null,"errorMessage":"IsDescending and AllDescending cannot both be specified on the [Index] attribute.","messagePattern":"IsDescending and AllDescending cannot both be specified on the \\[Index\\] attribute\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Abstractions/IndexAttribute.cs","lineNumber":75,"sourceCode":"    /// <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    {\n        get;\n        set\n        {\n            if (IsDescending is not null)\n            {\n                throw new ArgumentException(AbstractionsStrings.CannotSpecifyBothIsDescendingAndAllDescending);","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Abstractions/IndexAttribute.cs#L57-L93","documentation":"Thrown by the IndexAttribute.IsDescending setter when AllDescending has already been set to true. These two properties are mutually exclusive ways to express sort order, so EF Core forbids specifying both to avoid ambiguity. It fires at model-build time as soon as the conflicting assignment happens.","triggerScenarios":"Assigning AllDescending = true first, then later assigning IsDescending = ... on the same IndexAttribute instance. The setter checks the already-set AllDescending and throws.","commonSituations":"Copy-pasting configuration between indexes where one used AllDescending and another used IsDescending. Incrementally building up an index attribute in code and accidentally setting both flags. Refactoring from a global descending flag to per-column flags without clearing the old flag.","solutions":["Pick one mechanism: use IsDescending (per-column) OR AllDescending (uniform), never both.","If you previously set AllDescending and now want per-column control, do not reuse the same attribute instance, or reset state so only IsDescending is set.","Audit your IndexAttribute configuration to ensure the two properties are never assigned together."],"exampleFix":"// before\nvar idx = new IndexAttribute(\"A\", \"B\");\nidx.AllDescending = true;\nidx.IsDescending = new[] { true, false }; // throws\n\n// after\nvar idx = new IndexAttribute(\"A\", \"B\");\nidx.IsDescending = new[] { true, false }; // pick one mechanism","handlingStrategy":"validation","validationCode":"// Ensure mutual exclusion before assigning\nif (value is not null && indexAttr.AllDescending)\n{\n    throw new InvalidOperationException(\"IsDescending conflicts with AllDescending already set.\");\n}\nindexAttr.IsDescending = value;","typeGuard":"static bool CanSetIsDescending(IndexAttribute attr)\n    => !attr.AllDescending;","tryCatchPattern":null,"preventionTips":["Treat IsDescending and AllDescending as mutually exclusive; never assign both to one attribute.","Reset/avoid reusing attribute instances when switching sort-order strategy.","Add a unit test asserting only one of the two is ever set per index."],"tags":["ef-core","modeling","index","configuration","mutual-exclusion"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}