Efcore: Indexes on hidden fields breaks scaffolding

Created on 28 Jun 2019  路  4Comments  路  Source: dotnet/efcore

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.NotNullT
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.GetPropertyName(DatabaseColumn column)
at System.Linq.Enumerable.SelectListIterator2.ToArray() at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndex(EntityTypeBuilder builder, DatabaseIndex index)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitIndexes(EntityTypeBuilder builder, ICollection1 indexes) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTable(ModelBuilder modelBuilder, DatabaseTable table) at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitTables(ModelBuilder modelBuilder, ICollection1 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, IEnumerable1 tables, IEnumerable1 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, IEnumerable1 schemas, IEnumerable1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable1 schemaFilters, IEnumerable1 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):
https://github.com/aspnet/EntityFrameworkCore/issues/8192
https://github.com/aspnet/EntityFrameworkCore/pull/8276

closed-fixed customer-reported good first issue type-bug

Most helpful comment

@ajcvickers what is the proposed fix? Avoid including indexes with hidden columns in the DatabaseModel? I can create a PR...

All 4 comments

@ajcvickers what is the proposed fix? Avoid including indexes with hidden columns in the DatabaseModel? I can create a PR...

@ErikEJ That sounds right. @bricelam?

Sounds right

PR in progress, currently blocked by build issue #16656

Was this page helpful?
0 / 5 - 0 ratings