Skip to content

Commit d816afe

Browse files
authored
Revert "Fix View Indexes not Scaffolded in Sql Server (#37607)" (#37634)
This reverts commit 69eaf15.
1 parent 46436ac commit d816afe

2 files changed

Lines changed: 1 addition & 76 deletions

File tree

src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,13 +1039,6 @@ private void GetIndexes(DbConnection connection, IReadOnlyList<DatabaseTable> ta
10391039
{
10401040
using var command = connection.CreateCommand();
10411041
var commandText = @"
1042-
WITH [TablesAndViews] AS (
1043-
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped], [temporal_type]
1044-
FROM [sys].[tables]
1045-
UNION ALL
1046-
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped], 0 AS [temporal_type]
1047-
FROM [sys].[views]
1048-
)
10491042
SELECT
10501043
SCHEMA_NAME([t].[schema_id]) AS [table_schema],
10511044
[t].[name] AS [table_name],
@@ -1061,7 +1054,7 @@ FROM [sys].[views]
10611054
[ic].[is_descending_key],
10621055
[ic].[is_included_column]
10631056
FROM [sys].[indexes] AS [i]
1064-
JOIN [TablesAndViews] AS [t] ON [i].[object_id] = [t].[object_id]
1057+
JOIN [sys].[tables] AS [t] ON [i].[object_id] = [t].[object_id]
10651058
JOIN [sys].[index_columns] AS [ic] ON [i].[object_id] = [ic].[object_id] AND [i].[index_id] = [ic].[index_id]
10661059
JOIN [sys].[columns] AS [c] ON [ic].[object_id] = [c].[object_id] AND [ic].[column_id] = [c].[column_id]
10671060
WHERE [i].[is_hypothetical] = 0

test/EFCore.SqlServer.FunctionalTests/Scaffolding/SqlServerDatabaseModelFactoryTest.cs

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,74 +2012,6 @@ IndexProperty int
20122012
},
20132013
"DROP TABLE IndexTable;");
20142014

2015-
[ConditionalFact]
2016-
public void Create_indexes_on_views()
2017-
=> Test(
2018-
@"
2019-
CREATE TABLE dbo.BaseTable (
2020-
Id int NOT NULL,
2021-
Name int NOT NULL
2022-
);
2023-
2024-
-- Use EXEC to ensure CREATE VIEW is the start of its own batch
2025-
EXEC('
2026-
CREATE VIEW dbo.TestView
2027-
WITH SCHEMABINDING
2028-
AS
2029-
SELECT
2030-
Id,
2031-
Name,
2032-
COUNT_BIG(*) AS C
2033-
FROM dbo.BaseTable
2034-
GROUP BY Id, Name;
2035-
');
2036-
2037-
CREATE UNIQUE CLUSTERED INDEX IX_TestView_Id
2038-
ON dbo.TestView (Id);
2039-
",
2040-
[],
2041-
[],
2042-
(dbModel, scaffoldingFactory) =>
2043-
{
2044-
var view = dbModel.Tables.Single(t => t.Name == "TestView");
2045-
2046-
Assert.Single(view.Indexes);
2047-
2048-
var index = view.Indexes.Single();
2049-
Assert.True(index.IsUnique);
2050-
Assert.Collection(
2051-
index.Columns,
2052-
c => Assert.Equal("Id", c.Name));
2053-
2054-
var model = scaffoldingFactory.Create(dbModel, new ModelReverseEngineerOptions());
2055-
2056-
var viewEntity = model.GetEntityTypes()
2057-
.Single(e => e.Name == "TestView");
2058-
2059-
var properties = viewEntity.GetProperties().ToList();
2060-
Assert.Contains(properties, p => p.Name == "Id");
2061-
Assert.Contains(properties, p => p.Name == "Name");
2062-
2063-
Assert.Empty(viewEntity.GetKeys());
2064-
2065-
Assert.Collection(
2066-
viewEntity.GetIndexes(),
2067-
i =>
2068-
{
2069-
Assert.True(i.IsUnique);
2070-
Assert.Collection(
2071-
i.Properties,
2072-
p => Assert.Equal("Id", p.Name));
2073-
});
2074-
2075-
Assert.Empty(viewEntity.GetForeignKeys());
2076-
Assert.Empty(viewEntity.GetNavigations());
2077-
Assert.Empty(viewEntity.GetSkipNavigations());
2078-
},
2079-
@"
2080-
DROP VIEW dbo.TestView;
2081-
DROP TABLE dbo.BaseTable;");
2082-
20832015
[ConditionalFact]
20842016
public void Create_foreign_keys()
20852017
=> Test(

0 commit comments

Comments
 (0)