Running ef dbcontext scaffold results in the following exception:
System.ArgumentException: The collection argument 'propertyNames' must contain at least one element.
at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty[T](IReadOnlyList`1 value, String parameterName)
at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasIndex(String[] propertyNames, String name)
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, ModelReverseEngineerOptions 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 noPluarlize)
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)
I would like to share the verbose output and my SQL Schema with you but it's from work and i cannot share this information publicly.
EF Core version: Entity Framework Core .NET Command-line Tools 5.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10 20H2
IDE: Visual Studio 2019 16.8
Referenced nuget packages:
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.0" />
I did some testing and found the issue.
One of my table has a Columnstore index.
When I remove the columnstore index EF is able to generate a context and models from the database.
I also tried to generate the context using EF 3.1.10:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.10" />
</ItemGroup>
EF 3.1.10 is able to generate the context without any error. So this seams so be a new bug in EF 5.0.0
Edit 2
I tested some older 5.0 versions of EF and found that it worked until (including) 5.0.0-preview.8.20407.4. It stopped working from 5.0.0-rc.1.20451.13 and above.
@smitpatel Another scaffolding issue, this time with a columnstore index.
All of the columns in a columnstore index are stored in the metadata as included columns. The columnstore index doesn't have key columns.
So this seems to be coming from multiple issues. When we fixed #17083 we started identifying included columns. This left us without any of the columns from index itself. In #23083 we removed the included columns but still have detection to skip over. We need to remove index if there are no columns for it too.
3.1 behavior, scaffold all columns for columnstore index are added as a normal index.
If we add a check to skip index then it would still be different behavior. The syntax for columnstore index creation is slightly different from normal index. Should we start skipping as "breaking change" so we may be able to add columnstore index feature in future?
We have to use SQL to create/update our database schema. Our application only uses EF for some DB read/writes. For our usecase EF does not have to "know" about columnstore indexes. We do not use EF to mentain the schema nor do we need EF to generate any special queries. But EF should be able to generate model classes for all the tables (maybe by just ignoring unsported columnstore indexes).
Also not really related to this specific case but it would be nice if scaffold could include details about a schema problem in its error message. The only way for me to find the cause of this error was to remove parts of the schema until scaffold worked.. this try and error approach works but it is very time consuming.
Note from triage: we will bring this to Tactics for patch because the WorldWideImports sample database fails to reverse engineer because of this.
Most helpful comment
@smitpatel Another scaffolding issue, this time with a columnstore index.