Scaffold-DbContext: An item with the same key has already been added. — oracle-tech

    Forum Stats

  • 3,715,648 Users
  • 2,242,819 Discussions
  • 7,845,478 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Scaffold-DbContext: An item with the same key has already been added.

LeChuck
LeChuck Member Posts: 10 Red Ribbon
edited August 2019 in ODP.NET

Hi,

I'm currently testing a bit with the new Oracle.EntityFrameworkCore nuget, now that it's finally out. I have an existing database and I wanted to create the model for it.

So I'm using

Scaffold-DbContext "my data source goes here", Oracle.EntityFrameworkCore -OutputDir Models

Then this is happening:

2019-04-05 14:28:43.229796 ThreadID:1 (SQL) OracleDatabaseModelFactory.GetColumns() : SELECT sys_context('userenv', 'current_schema') as schema, c.table_name, c.column_name, c.column_id, c.data_type, c.char_length, c.data_length, c.data_precision, c.data_scale, c.nullable, c.identity_column, c.data_default, c.virtual_column, c.hidden_column, c.user_generated FROM user_tab_cols c INNER JOIN user_tables t  ON t.table_name=c.table_name WHERE t.table_name <> '__EFMigrationsHistory'  ORDER BY c.column_id

2019-04-05 14:28:43.705787 ThreadID:1 (SQL) OracleDatabaseModelFactory.GetTriggerColumns() : select column_name from USER_TRIGGER_COLS where table_name ='AENDERUNGSPROTOKOLLIERUNG'

2019-04-05 14:28:46.883521 ThreadID:1 (MAP) OracleDatabaseModelFactory.GetTriggerColumns() : trigger column name: ID

2019-04-05 14:28:46.883571 ThreadID:1 (MAP) OracleDatabaseModelFactory.GetTriggerColumns() : trigger column name: AUFGABE

2019-04-05 14:28:46.883578 ThreadID:1 (MAP) OracleDatabaseModelFactory.GetTriggerColumns() : trigger column name: BENUTZER

2019-04-05 14:28:46.883588 ThreadID:1 (MAP) OracleDatabaseModelFactory.GetTriggerColumns() : trigger column name: TYP

2019-04-05 14:28:46.883593 ThreadID:1 (MAP) OracleDatabaseModelFactory.GetTriggerColumns() : trigger column name: ID

2019-04-05 14:28:46.897957 ThreadID:1   (ERROR)   OracleDatabaseModelFactory.GetTriggerColumns() :  System.ArgumentException: An item with the same key has already been added. Key: ID

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTriggerColumns(DbConnection connection, String table)

2019-04-05 14:28:46.898385 ThreadID:1   (ERROR)   OracleDatabaseModelFactory.GetColumns() :  System.ArgumentException: An item with the same key has already been added. Key: ID

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTriggerColumns(DbConnection connection, String table)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetColumns(DbConnection connection, String tableFilter, DatabaseModel databaseModel)

2019-04-05 14:28:46.898496 ThreadID:1   (ERROR)   OracleDatabaseModelFactory.GetTables() :  System.ArgumentException: An item with the same key has already been added. Key: ID

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTriggerColumns(DbConnection connection, String table)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetColumns(DbConnection connection, String tableFilter, DatabaseModel databaseModel)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTables(DbConnection connection, Func`3 tableFilter, DatabaseModel databaseModel)

2019-04-05 14:28:46.912912 ThreadID:1   (ERROR)   OracleDatabaseModelFactory.Create() :  System.ArgumentException: An item with the same key has already been added. Key: ID

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTriggerColumns(DbConnection connection, String table)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetColumns(DbConnection connection, String tableFilter, DatabaseModel databaseModel)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTables(DbConnection connection, Func`3 tableFilter, DatabaseModel databaseModel)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.Create(DbConnection connection, IEnumerable`1 tables, IEnumerable`1 schemas)

System.ArgumentException: An item with the same key has already been added. Key: ID

   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTriggerColumns(DbConnection connection, String table)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetColumns(DbConnection connection, String tableFilter, DatabaseModel databaseModel)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.GetTables(DbConnection connection, Func`3 tableFilter, DatabaseModel databaseModel)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.Create(DbConnection connection, IEnumerable`1 tables, IEnumerable`1 schemas)

   at Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory.Create(String connectionString, IEnumerable`1 tables, IEnumerable`1 schemas)

   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.ReverseEngineerScaffolder.ScaffoldModel(String connectionString, IEnumerable`1 tables, IEnumerable`1 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, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 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.<Execute>b__0()

   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

An item with the same key has already been added. Key: ID

I don't know why you only filter on the table_name when you query USER_TRIGGER_COLS.

select column_name from USER_TRIGGER_COLS where table_name ='AENDERUNGSPROTOKOLLIERUNG'

Problem is, that this table has 2 triggers, and both use column "ID". This table shows briefly the content of USER_TRIGGER_COLS for that table:

TRIGGER_NAMETABLE_NAMECOLUMN_NAMECOLUMN_USAGE
TR$AENDPRTOAFTERAENDERUNGSPROTOKOLLIERUNGIDNEW IN
TR$AENDPRTOAFTERAENDERUNGSPROTOKOLLIERUNGAUFGABENEW IN
TR$AENDPRTOAFTERAENDERUNGSPROTOKOLLIERUNGBENUTZERNEW IN
TR$AENDPRTOAFTERAENDERUNGSPROTOKOLLIERUNGTYPNEW IN
TR$AENDPRTOBEFOREAENDERUNGSPROTOKOLLIERUNGIDNEW OUT

Would be nice if this can be fixed.

Thanks,

Markus

Answers

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited April 2019

    Thanks for reporting the bug, Markus. This has been filed as bug 29611320.

  • LeChuck
    LeChuck Member Posts: 10 Red Ribbon
    edited April 2019

    Is this the correct bug id? It doesn't find a bug with that id.

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited April 2019

    It's the corred Bug ID. You may not be able to view it because Oracle EF Core is currently in "beta" mode. Beta bugs, unfortunately, are not viewable to the public.

  • Nirav.Bhatt
    Nirav.Bhatt Member Posts: 7
    edited July 2019

    Hi Alex,

    I am currently using below packages.

    <PackageReference Include="Oracle.EntityFrameworkCore" Version="2.19.30" />

    <PackageReference Include="Oracle.ManagedDataAccess.Core" Version="2.19.31" />

    Code in Startup.cs

    services.AddEntityFrameworkOracle()

      .AddDbContext< ApplicationDbContext>((serviceProvider, options) =>

       options.UseOracle(connectionString)

      .UseInternalServiceProvider(serviceProvider));

    I am trying to scaffold my current database with below command.

    dotnet-ef dbcontext scaffold "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=pdb1)));User Id=user1;Password=password;" Oracle.EntityFrameworkCore -o "Entities" -s "..\Web\Web.csproj"

    I am receiving below error.

    System.TypeLoadException: Method 'Create' in type 'Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.

       at Oracle.EntityFrameworkCore.Design.Internal.OracleDesignTimeServices.ConfigureDesignTimeServices(IServiceCollection serviceCollection)

       at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureDesignTimeServices(Type designTimeServicesType, IServiceCollection services)

       at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)

       at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)

       at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(String provider, String connectionString, String outputDir, String outputContextDir, String dbContextClassName, IEnumerable`1 schemas, IEnumerable`1 tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)

       at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable`1 schemaFilters, IEnumerable`1 tableFilters, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)

       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)

    Method 'Create' in type 'Oracle.EntityFrameworkCore.Scaffolding.Internal.OracleDatabaseModelFactory' from assembly 'Oracle.EntityFrameworkCore, Version=2.0.19.1, Culture=neutral, PublicKeyToken=89b483f429c47342' does not have an implementation.

    Is the issue still open or it should be fixed in prod release.

    Also I have observed that even if the package is 2.0.19.30 the binary available in package is 2.0.19.1.

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited July 2019

    Which version of EF Core are you using?

  • Nirav.Bhatt
    Nirav.Bhatt Member Posts: 7
    edited July 2019

    I am using EF Core 3.0

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited August 2019

    EF Core 3.0 is not supported yet, which is why you are seeing this error.

Sign In or Register to comment.