Indexes on hidden fields breaks scaffolding #16316
Labels
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
good first issue
This issue should be relatively straightforward to fix.
type-bug
Milestone
When an index is created on a hidden field, scaffolding throws an unfriendly error. While I don't necessarily think it needs to continue to function, I think the error should at least point out which index/field it is having issues with.
For example, this index would cause an issue (where SysEndTime is hidden):
CREATE NONCLUSTERED INDEX [ix_TableName_SysStartTimeSysEndTime] ON [dbo].[TableName] ([SysStartTime],[SysEndTime]) INCLUDE ([Id],[Amount])
Error message:
Value cannot be null.
Parameter name: column
Stack trace:
System.ArgumentNullException: Value cannot be null.
Parameter name: column
at Microsoft.EntityFrameworkCore.Utilities.Check.NotNull[T](T value, String parameterName)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetPropertyName(DatabaseColumn column)
at System.Linq.Enumerable.SelectListIterator
2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable
1 source)at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndex(EntityTypeBuilder builder, DatabaseIndex index)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndexes(EntityTypeBuilder builder, ICollection
1 indexes) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection
1 tables)at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable
1 tables, IEnumerable
1 schemas, String namespace, String language, String contextDir, String contextName, 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, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable
1 schemaFilters, IEnumerable
1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContext.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
EF Core version: 2.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10
See the following for issues I think are related to this (aka when the issue was introduced):
#8192
#8276
The text was updated successfully, but these errors were encountered: