EFCorePowerTools: CLI is throwing Exception The key {'Id'} cannot be added to keyless type '(Dictionary)' although I am excluding all tables

I wanted only few stored procs so I marked all (tables, functions, views and SPs) with filter: “exclusionWildcard”: “*” and then added [“exclude”: false] to the stored procs I wanted to reverse engineer. I get the following error complaining about this table <Table_name_in_my_DB> although I am excluding all tables. May be I am missing something here. I checked SQL and that table did not have a PK constraint. I could not do anything since I don’t have enough permissions to Alter the table and see if this solves the issue.

System.InvalidOperationException: The key {‘Id’} cannot be added to keyless type ‘<Table_name_in_my_DB>(Dictionary<string, object>)’. at Key Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.AddKey(IReadOnlyList<Property> properties, ConfigurationSource configurationSource) at IMutableKey Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType.AddKey(IReadOnlyList<IMutableProperty> properties) at IMutableForeignKey Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitForeignKey(ModelBuilder modelBuilder, DatabaseForeignKey foreignKey) at ModelBuilder Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitForeignKeys(ModelBuilder modelBuilder, IList<DatabaseForeignKey> foreignKeys) at ModelBuilder Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitDatabaseModel(ModelBuilder modelBuilder, DatabaseModel databaseModel) at IModel Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.Create(DatabaseModel databaseModel, ModelReverseEngineerOptions options) at ScaffoldedModel RevEng.Core.ReverseEngineerScaffolder.ScaffoldModel(string connectionString, DatabaseModelFactoryOptions databaseOptions, ModelReverseEngineerOptions modelOptions, ModelCodeGenerationOptions codeOptions, bool removeNullableBoolDefaults, bool dbContextOnly, bool entitiesOnly, bool useSchemaFolders) in ReverseEngineerScaffolder.cs:371 at SavedModelFiles RevEng.Core.ReverseEngineerScaffolder.GenerateDbContext(ReverseEngineerCommandOptions options, List<string> schemas, string outputContextDir, string modelNamespace, string contextNamespace , string projectPath, string outputPath) in ReverseEngineerScaffolder.cs:102 at ReverseEngineerResult RevEng.Core.ReverseEngineerRunner.GenerateFiles(ReverseEngineerCommandOptions options) in ReverseEngineerRunner.cs:81 at ReverseEngineerResult ErikEJ.EFCorePowerTools.HostedServices.ScaffoldHostedService.<>c__DisplayClass6_0.<ExecuteAsync>b__0() in ScaffoldHostedService.cs:83 at void ErikEJ.EFCorePowerTools.Services.DisplayService.<>c__DisplayClass7_01.<Wait>b__0(StatusContext ctx) in DisplayService.cs:63 at Task Spectre.Console.Status.<>c__DisplayClass14_0.<Start>b__0(StatusContext ctx) in Status.cs:44 at void Spectre.Console.Status.<>c__DisplayClass16_0.<<StartAsync>b__0>d.MoveNext() in Status.cs:79 at void Spectre.Console.Status.<>c__DisplayClass17_01.<<StartAsync>b__0>d.MoveNext() in Status.cs:120 at void Spectre.Console.Progress.<>c__DisplayClass28_0`1.<<StartAsync>b__0>d.MoveNext() in Progress.cs:133 at async Task<T> Spectre.Console.Internal.DefaultExclusivityMode.RunAsync<T>(Func<Task<T>> func) in DefaultExclusivityMode.cs:40 at async Task<T> Spectre.Console.Progress.StartAsync<T>(Func<ProgressContext, Task<T>> action) in Progress.cs:116 at async Task<T> Spectre.Console.Status.StartAsync<T>(string status, Func<StatusContext, Task<T>> func) in Status.cs:117 at async Task Spectre.Console.Status.StartAsync(string status, Func<StatusContext, Task> action) in Status.cs:77 at void Spectre.Console.Status.Start(string status, Action<StatusContext> action) in Status.cs:48 at T ErikEJ.EFCorePowerTools.Services.DisplayService.Wait<T>(string message, Func<T> doFunc) in DisplayService.cs:58 at async Task ErikEJ.EFCorePowerTools.HostedServices.ScaffoldHostedService.ExecuteAsync(CancellationToken stoppingToken) in ScaffoldHostedService.cs:81 at async Task Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken) at async Task<IHost> Microsoft.Extensions.Hosting.HostingAbstractionsHostBuilderExtensions.StartAsync(IHostBuilder hostBuilder, CancellationToken cancellationToken)

Provide steps to reproduce

Please include a complete description or project that I can redo/run to reproduce the issue.

Provide technical details

EF Core Power Tools 6.0.0-rc.2 and 7.0.0-rc.2

  • EF Core version in use: EF Core 7

  • Database engine: SQL Server

“code-generation”: { “enable-on-configuring”: false, “type”: “all”, “use-database-names”: false, “use-data-annotations”: false, “use-nullable-reference-types”: false, “use-inflector”: false, “use-legacy-inflector”: false, “use-many-to-many-entity”: false, “use-t4”: false, “remove-defaultsql-from-bool-properties”: false, “soft-delete-obsolete-files”: false, “discover-multiple-stored-procedure-resultsets-preview”: false, “use-alternate-stored-procedure-resultset-discovery”: false }

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 17 (9 by maintainers)

Most upvoted comments

@xheox yeah, maybe it should be skipping all tables and views, but currently it is not happening, as stored procs are not supported by the built-in scaffolding.

I think it might be an issue to skip it, as the DbContext will not be generated then. Maybe you can opt-in to scaffold a single table as a workaround by setting exclude: false for a single (dummy) table?

I suggest installing and try to run “dotnet ef dbcontext scaffold”