System.ArgumentException: The collection argument 'propertyNames' must contain at least one element.

See original GitHub issue

System.ArgumentException: The collection argument ‘propertyNames’ must contain at least one element.

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.

Include provider and version information

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" />

Edit

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
ajcvickerscommented, Nov 18, 2020

@smitpatel Another scaffolding issue, this time with a columnstore index.

1reaction
smitpatelcommented, Nov 18, 2020

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The collection argument 'foreignKeyPropertyNames' must ...
System.ArgumentException: The collection argument 'foreignKeyPropertyNames' must contain at least one element. at Microsoft.
Read more >
The collection argument 'foreignKeyPropertyNames' must ...
Coding example for the question The collection argument 'foreignKeyPropertyNames' must contain at least one element-entityframework core.
Read more >
Entity Framework latest version - Awesome .NET - LibHunt
ArgumentException: The collection argument 'propertyNames' must contain at least one element · Collations aren't scaffolded correctly. SaveChanges.
Read more >
AbstractionsStrings.CollectionArgumentIsEmpty(Object) ...
The collection argument '{argumentName}' must contain at least one element.
Read more >
dotnet/efcore v5.0.1 on GitHub
ArgumentException: The collection argument 'propertyNames' must contain at least one element · Collations aren't scaffolded correctly. SaveChanges.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found