From fa745b6aa37b67c15d4c324dc7e3de2e825ac7b9 Mon Sep 17 00:00:00 2001 From: ErikEJ Date: Tue, 21 Apr 2020 18:10:54 +0200 Subject: [PATCH 1/2] Ignore hypothetical indexes (now with test!) fixes #20705 --- .../Internal/SqlServerDatabaseModelFactory.cs | 1 + .../SqlServerDatabaseModelFactoryTest.cs | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs index df7caeeb86d..923d389ab3b 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs @@ -867,6 +867,7 @@ FROM [sys].[indexes] i commandText += @" AND [c].[is_hidden] = 1 + AND [i].[is_hypothetical] = 0 )"; } diff --git a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs index ab2e9bee668..4a706b1753d 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs @@ -1880,6 +1880,26 @@ CREATE TABLE FilteredIndexTable ( "DROP TABLE FilteredIndexTable;"); } + [ConditionalFact] + public void Ignore_hypothetical_index() + { + Test( + @" +CREATE TABLE HypotheticalIndexTable ( + Id1 int, + Id2 int NULL, +); + +CREATE INDEX ixHypo ON HypotheticalIndexTable ( Id1 ) WITH STATISTICS_ONLY = -1;", + Enumerable.Empty(), + Enumerable.Empty(), + dbModel => + { + Assert.Empty(dbModel.Tables.Single().Indexes); + }, + "DROP TABLE HypotheticalIndexTable;"); + } + #endregion #region ForeignKeyFacets From 44f1aa5d83e65952d93ed5c5697fa069b49cba48 Mon Sep 17 00:00:00 2001 From: ErikEJ Date: Tue, 21 Apr 2020 20:08:32 +0200 Subject: [PATCH 2/2] Fixup --- .../Scaffolding/Internal/SqlServerDatabaseModelFactory.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs index 923d389ab3b..42880677b6f 100644 --- a/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs +++ b/src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs @@ -849,7 +849,8 @@ FROM [sys].[indexes] AS [i] JOIN [sys].[tables] AS [t] ON [i].[object_id] = [t].[object_id] JOIN [sys].[index_columns] AS [ic] ON [i].[object_id] = [ic].[object_id] AND [i].[index_id] = [ic].[index_id] JOIN [sys].[columns] AS [c] ON [ic].[object_id] = [c].[object_id] AND [ic].[column_id] = [c].[column_id] -WHERE " +WHERE [i].[is_hypothetical] = 0 +AND " + tableFilter; if (SupportsTemporalTable())