Regression in 11.0.0: Scaffold-DbContext fails with "Invalid column name 'temporal_type'" on SQL Server 2012/2014
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu với GetIndexes trong src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs và so sánh các kiểm tra bảng temporal với GetTables và GetColumns. Tái hiện lỗi scaffolding trên SQL Server 2012 hoặc 2014, sau đó thêm hoặc cập nhật kiểm thử hồi quy cho phiên bản engine đó. Công việc hoàn tất khi scaffolding không còn truy vấn cột temporal_type không khả dụng và kiểm thử hồi quy chạy thành công.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
After upgrading to EF Core 11.0.0, running Scaffold-DbContext against a SQL Server 2012 (11.x, compatibility level 110) database fails with Microsoft.Data.SqlClient.SqlException: Invalid column name 'temporal_type' inside SqlServerDatabaseModelFactory.GetIndexes.
The exact same scaffolding command works without issue on EF Core 10.0.15.
Root cause
This regression was introduced in #37607 (Fix View Indexes not Scaffolded in Sql Server).
In src/EFCore.SqlServer/Scaffolding/Internal/SqlServerDatabaseModelFactory.cs, GetIndexes defines a [TablesAndViews] CTE that unconditionally selects [temporal_type] from [sys].[tables]:
WITH [TablesAndViews] AS (
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped], [temporal_type]
FROM [sys].[tables]
UNION ALL
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped], 0 AS [temporal_type]
FROM [sys].[views]
)
Because sys.tables.temporal_type was introduced in SQL Server 2016 (13.x), this query fails on SQL Server 2012 / 2014 engines even though SupportsTemporalTable (_compatibilityLevel >= 130 && IsFullFeaturedEngineEdition) is properly checked everywhere else in SqlServerDatabaseModelFactory (GetTables, GetColumns, and the subquery later in GetIndexes).
(Side note: the CTE also queries [sys].[views] unconditionally without checking SupportsViews.)
Suggested fix
Guard the [temporal_type] projection in the CTE with SupportsTemporalTable:
WITH [TablesAndViews] AS (
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped]{(SupportsTemporalTable ? ", [temporal_type]" : "")}
FROM [sys].[tables]
UNION ALL
SELECT [object_id], [schema_id], [name], [type], [is_ms_shipped]{(SupportsTemporalTable ? ", 0 AS [temporal_type]" : "")}
FROM [sys].[views]
)
Workaround
Downgrading EF Core packages (Microsoft.EntityFrameworkCore, .SqlServer, .Design, .Tools) to 10.0.15 restores scaffolding functionality.
Your code
Minimal `.csproj`:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net11.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="11.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="11.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="11.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="11.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Command executed in Package Manager Console against a SQL Server 2012 (11.x) database:
Scaffold-DbContext "Server=<server>;Database=<db>;User Id=<user>;Password=<password>;TrustServerCertificate=True" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Entities -Force -Context Context -ContextDir Contexts -NoOnConfiguring
Stack traces
Build started...
Build succeeded.
Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid column name 'temporal_type'.
at Microsoft.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.Connection.SqlConnectionInternal.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at Microsoft.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, SqlCommand command, Boolean callerHasConnectionLock, Boolean asyncClose)
at Microsoft.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at Microsoft.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
at Microsoft.Data.SqlClient.SqlDataReader.get_MetaData()
at Microsoft.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean isAsync, Int32 timeout, Task& task, Boolean asyncWrite, Boolean isRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, TaskCompletionSource`1 completion, Int32 timeout, Task& executeTask, Boolean& usedCache, Boolean asyncWrite, Boolean isRetry, String method)
at Microsoft.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
at Microsoft.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.GetIndexes(DbConnection connection, IReadOnlyList`1 tables, String tableFilter)
at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.GetTables(DbConnection connection, DatabaseModel databaseModel, Func`3 tableFilter, IReadOnlyDictionary`2 typeAliases, String databaseCollation)
at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(DbConnection connection, DatabaseModelFactoryOptions options)
at Microsoft.EntityFrameworkCore.SqlServer.Scaffolding.Internal.SqlServerDatabaseModelFactory.Create(String connectionString, DatabaseModelFactoryOptions options)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions)
at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, String modelNamespace, String contextNamespace, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames, Boolean suppressOnConfiguring, Boolean noPluralize)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
ClientConnectionId :984639a9-e7b1-4af1-96df-9ed8bc0f1390
Error Number :207,State :1,Class :16
Invalid column name 'temporal_type'.
Verbose output
EF Core version
11.0.0
Database provider
Microsoft.EntityFrameworkCore.SqlServer
Target framework
.NET 11.0
Operating system
Windows
IDE
Visual Studio Professional 2026 (Package Manager Console)
- Ngôn ngữ chính
- C#
- Star
- 14.8k
- Fork
- 3.5k
- Merge trung bình
- 3 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 182
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của dotnet/efcore
-
GroupBy element `OrderBy(...).First()`/`MaxBy` over an owned type mapped to its own table fails to translateCó thể đã có người làm @cincuranet đã nhận hôm nay. Đang mởarea-groupby area-query
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
dotnet/efcore#39833 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
SQLite: Polygon.Length translates to GLength, which returns 0Có thể đã có người làm @cincuranet đã nhận hôm nay. Đang mởarea-query area-sqlite
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 45/100
dotnet/efcore#39826 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Migration lock with LockReleaseBehavior.Transaction doesn't prevent concurrent migrations since per-migration transactionsCó thể đã có người làm @AndriySvyryd đã nhận 1 ngày trước. Đang mởarea-migrations
dotnet/efcore#39824 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Querying a TPC base type with a JSON complex property throwsCó thể đã có người làm @cincuranet đã nhận 1 ngày trước. Đang mởarea-query
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
dotnet/efcore#39814 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Three Cosmos structural-equality tests flaky on Cosmos DB Emulator for WindowsCó thể đã có người làm @su-senka đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 35/100
dotnet/efcore#39809 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của dotnet/efcore
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
SubtitleEdit/subtitleedit#17247 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Restore test cleanup fails on Windows when restored files are read-onlyCó thể đã có người làm @JamBalaya56562 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
duplicati/duplicati#8046 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Bundles Documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pyrevitlabs/pyRevit#4285 ·
Maintainer thường phản hồi trong vòng 1 ngày