{"record":{"id":"c07753aefc514926","repo":"dotnet/efcore","slug":"the-indexes-index1-on-entitytype1-and-index-c07753","errorCode":null,"errorMessage":"The indexes {index1} on '{entityType1}' and {index2} on '{entityType2}' are both mapped to '{table}.{indexName}', but with different sort orders.","messagePattern":"The indexes (.+?) on '(.+?)' and (.+?) on '(.+?)' are both mapped to '(.+?)\\.(.+?)', but with different sort orders\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs","lineNumber":99,"sourceCode":"        }\n\n        return index.IsUnique != duplicateIndex.IsUnique\n            ? shouldThrow\n                ? throw new InvalidOperationException(\n                    RelationalStrings.DuplicateIndexUniquenessMismatch(\n                        index.DisplayName(),\n                        index.DeclaringEntityType.DisplayName(),\n                        duplicateIndex.DisplayName(),\n                        duplicateIndex.DeclaringEntityType.DisplayName(),\n                        index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                        index.GetDatabaseName(storeObject)))\n                : false\n            : (index.IsDescending is null) != (duplicateIndex.IsDescending is null)\n            || (index.IsDescending is not null\n                && duplicateIndex.IsDescending is not null\n                && !index.IsDescending.SequenceEqual(duplicateIndex.IsDescending))\n                ? shouldThrow\n                    ? throw new InvalidOperationException(\n                        RelationalStrings.DuplicateIndexSortOrdersMismatch(\n                            index.DisplayName(),\n                            index.DeclaringEntityType.DisplayName(),\n                            duplicateIndex.DisplayName(),\n                            duplicateIndex.DeclaringEntityType.DisplayName(),\n                            index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                            index.GetDatabaseName(storeObject)))\n                    : false\n                : index.GetFilter(storeObject) == duplicateIndex.GetFilter(storeObject)\n                || (shouldThrow\n                    ? throw new InvalidOperationException(\n                        RelationalStrings.DuplicateIndexFiltersMismatch(\n                            index.DisplayName(),\n                            index.DeclaringEntityType.DisplayName(),\n                            duplicateIndex.DisplayName(),\n                            duplicateIndex.DeclaringEntityType.DisplayName(),\n                            index.DeclaringEntityType.GetSchemaQualifiedTableName(),\n                            index.GetDatabaseName(storeObject),","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/RelationalIndexExtensions.cs#L81-L117","documentation":"Two indexes share the same database name and table but define different descending/ascending sort orders (IsDescending). The database cannot represent conflicting collation orders for one index.","triggerScenarios":"RelationalIndexExtensions.AreCompatible with shouldThrow:true when (index.IsDescending is null) != (duplicateIndex.IsDescending is null), or both non-null but not SequenceEqual. Triggered by HasIndex(...).IsDescending(...) values that mismatch across two indexes sharing a database name.","commonSituations":"EF7+ descending-index support used inconsistently on colliding indexes; one index left at default (null IsDescending) and another explicitly setting descending; copy/paste of HasDatabaseName across index definitions with different sort orders.","solutions":["Align the IsDescending configuration on both indexes.","Give the indexes distinct database names via HasDatabaseName.","Remove one of the conflicting index definitions.","If only one sort order is meaningful, delete the other index."],"exampleFix":"// before\nmodelBuilder.Entity<Log>().HasIndex(l => l.Ts).IsDescending().HasDatabaseName(\"IX_Log_Ts\");\nmodelBuilder.Entity<LogArchive>().ToTable(\"Log\").HasIndex(l => l.Ts).HasDatabaseName(\"IX_Log_Ts\");\n\n// after: align sort order\nmodelBuilder.Entity<LogArchive>().ToTable(\"Log\").HasIndex(l => l.Ts).IsDescending().HasDatabaseName(\"IX_Log_Ts\");","handlingStrategy":"validation","validationCode":"// Detect sort-order mismatches for colliding index names.\nvar groups = modelBuilder.Model.GetEntityTypes()\n    .SelectMany(e => e.GetDeclaredIndexes())\n    .GroupBy(i => new { Name = i.GetDatabaseName(), Table = i.DeclaringEntityType.GetSchemaQualifiedTableName() })\n    .Where(g => g.Count() > 1);\nforeach (var g in groups)\n{\n    var orders = g.Select(i => i.IsDescending == null ? \"null\" : string.Join(\",\", i.IsDescending)).Distinct();\n    if (orders.Count() > 1)\n        Console.WriteLine($\"Index '{g.Key.Name}' has conflicting sort orders.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When using IsDescending, set it explicitly on every colliding index to the same value.","Treat descending-order config as load-bearing and review it during PRs.","Add a model validation test."],"tags":["ef-core","relational-metadata","index","sort-order","model-validation"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}