Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexes on hidden fields breaks scaffolding #16316

Closed
tmjac2 opened this issue Jun 27, 2019 · 4 comments · Fixed by #16681
Closed

Indexes on hidden fields breaks scaffolding #16316

tmjac2 opened this issue Jun 27, 2019 · 4 comments · Fixed by #16681
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

Comments

@tmjac2
Copy link

tmjac2 commented Jun 27, 2019

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.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):
#8192
#8276

@ajcvickers ajcvickers added this to the Backlog milestone Jul 1, 2019
@ajcvickers ajcvickers added good first issue This issue should be relatively straightforward to fix. customer-reported labels Jul 1, 2019
@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 13, 2019

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

@ajcvickers
Copy link
Member

@ErikEJ That sounds right. @bricelam?

@bricelam
Copy link
Contributor

Sounds right

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 20, 2019

PR in progress, currently blocked by build issue #16656

ErikEJ added a commit to ErikEJ/EntityFramework that referenced this issue Jul 20, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 3.0.0 Jul 24, 2019
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jul 24, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0, 3.0.0-preview8 Jul 29, 2019
@ajcvickers ajcvickers modified the milestones: 3.0.0-preview8, 3.0.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants