dotnet ef dbcontext scaffold: The property list {'Id', 'Id'} cannot be used, because it contains a d — oracle-tech

    Forum Stats

  • 3,715,657 Users
  • 2,242,821 Discussions
  • 7,845,481 Comments

Discussions

Howdy, Stranger!

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

dotnet ef dbcontext scaffold: The property list {'Id', 'Id'} cannot be used, because it contains a d

4180700
4180700 Member Posts: 2
edited March 2020 in ODP.NET

I tried to create model classes for my Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production database with dotnet ef.

CREATE TABLE Demo (    Id INTEGER PRIMARY KEY,    Name VARCHAR(200));

Scaffold command for table DEMO on Windows 10:

dotnet ef dbcontext scaffold  "User Id=(user);Password=(pass);Data Source=localhost:1521/orcl" Oracle.EntityFrameworkCore --output-dir Model --force --data-annotations -t DEMO -v

This produces an error: The property list {'Id', 'Id'} cannot be used, because it contains a duplicate - 'Id'.. It seems that the tool wants to create a property for the column and for the index. I tried different versions for the project and the dotnet-ef tool (.NET 2.1 and 3.1), nothing worked for me.

Output of dotnet ef

Using project 'C:\Users\Michael\Desktop\OracleDemo\OracleDemo.csproj'.Using startup project 'C:\Users\Michael\Desktop\OracleDemo\OracleDemo.csproj'.Writing 'C:\Users\Michael\Desktop\OracleDemo\obj\OracleDemo.csproj.EntityFrameworkCore.targets'...dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Michael\AppData\Local\Temp\tmpFD99.tmp /verbosity:quiet /nologo C:\Users\Michael\Desktop\OracleDemo\OracleDemo.csprojWriting 'C:\Users\Michael\Desktop\OracleDemo\obj\OracleDemo.csproj.EntityFrameworkCore.targets'...dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\Michael\AppData\Local\Temp\tmpFFCD.tmp /verbosity:quiet /nologo C:\Users\Michael\Desktop\OracleDemo\OracleDemo.csprojBuild started...dotnet build C:\Users\Michael\Desktop\OracleDemo\OracleDemo.csproj /verbosity:quiet /nologoBuild succeeded.    0 Warning(s)    0 Error(s)Time Elapsed 00:00:01.01Build succeeded.dotnet exec --depsfile C:\Users\Michael\Desktop\OracleDemo\bin\Debug\netcoreapp2.1\OracleDemo.deps.json --additionalprobingpath C:\Users\Michael\.nuget\packages --additionalprobingpath C:\Microsoft\Xamarin\NuGet --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\Michael\Desktop\OracleDemo\bin\Debug\netcoreapp2.1\OracleDemo.runtimeconfig.json C:\Users\Michael\.dotnet\tools\.store\dotnet-ef\3.1.1\dotnet-ef\3.1.1\tools\netcoreapp3.1\any\tools\netcoreapp2.0\any\ef.dll dbcontext scaffold "User Id=User2;Password=oracle;Data Source=localhost:1521/orcl" Oracle.EntityFrameworkCore --output-dir Model --force --data-annotations -t DEMO --assembly C:\Users\Michael\Desktop\OracleDemo\bin\Debug\netcoreapp2.1\OracleDemo.dll --startup-assembly C:\Users\Michael\Desktop\OracleDemo\bin\Debug\netcoreapp2.1\OracleDemo.dll --project-dir C:\Users\Michael\Desktop\OracleDemo\ --language C# --working-dir C:\Users\Michael\Desktop\OracleDemo --verbose --root-namespace OracleDemoUsing assembly 'OracleDemo'.Using startup assembly 'OracleDemo'.Using application base 'C:\Users\Michael\Desktop\OracleDemo\bin\Debug\netcoreapp2.1'.Using working directory 'C:\Users\Michael\Desktop\OracleDemo'.Using root namespace 'OracleDemo'.Using project directory 'C:\Users\Michael\Desktop\OracleDemo\'.Finding design-time services for provider 'Oracle.EntityFrameworkCore'...Using design-time services from provider 'Oracle.EntityFrameworkCore'.Finding design-time services referenced by assembly 'OracleDemo'.No referenced design-time services were found.Finding IDesignTimeServices implementations in assembly 'OracleDemo'...No design-time services were found.Found default schema USER2.Found table with name: USER2.DEMO.Found column with table: USER2.DEMO, column name: ID, ordinal: 1, data type: NUMBER, maximum length: 0, precision: 0, scale: 0, nullable: False, identity: False, default value: (null), computed value: (null)Found column with table: USER2.DEMO, column name: NAME, ordinal: 2, data type: VARCHAR2, maximum length: 200, precision: 0, scale: 0, nullable: True, identity: False, default value: (null), computed value: (null)Found primary key with name: SYS_C0012903, table: USER2.DEMO.Found index with name: SYS_C0012903, table: USER2.DEMO, is unique: True.System.InvalidOperationException: The property list {'Id', 'Id'} cannot be used, because it contains a duplicate - 'Id'.   at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.AddKey(IReadOnlyList`1 properties, ConfigurationSource configurationSource)   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasKeyInternal(IReadOnlyList`1 properties, Nullable`1 configurationSource)   at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.PrimaryKey(IReadOnlyList`1 properties, ConfigurationSource configurationSource)   at Microsoft.EntityFrameworkCore.Metadata.Builders.EntityTypeBuilder.HasKey(String[] propertyNames)   at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitPrimaryKey(EntityTypeBuilder builder, DatabaseTable table)   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, Boolean useDatabaseNames)   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)The property list {'Id', 'Id'} cannot be used, because it contains a duplicate - 'Id'.
3818723

Best Answer

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited January 2020 Accepted Answer

    In this DB, do you have another schema with a table with the same name that contains a primary key column with the same name, "Id"? If so, then you are very likely hitting Bug 30664978. The Oracle dev team is working on a fix. To workaround this bug for now, you can change the name of the table or primary key column name of either of the tables.

Answers

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited January 2020 Accepted Answer

    In this DB, do you have another schema with a table with the same name that contains a primary key column with the same name, "Id"? If so, then you are very likely hitting Bug 30664978. The Oracle dev team is working on a fix. To workaround this bug for now, you can change the name of the table or primary key column name of either of the tables.

  • 4180700
    4180700 Member Posts: 2
    edited February 2020

    Thanks for the advice. There was a table with the same name, but in a different schema where this user had rights on it (user was DBA in my test database). Creating a user with CONNECT, RESOURCE privileges solved the problem.

  • 3818723
    3818723 Member Posts: 7
    edited February 2020

    Hello Alex,

    we are affected by the same problem user 4180700 mentioned. I would like to know more details but have no access to Bug #30664978 .

    Requested Bug could not be displayed. Possible reasons are:

    • The bug id was entered incorrectly. Please check and try again.
    • The bug id does not exist (was referenced incorrectly).
    • The bug is not classified as publicly accessible ("non-public").
    • The content is being updated and it is temporarily unavailable but will be made available again soon.
  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited February 2020

    I just enabled the bug to be publicly viewable. You should see it now in My Oracle Support.

  • 3818723
    3818723 Member Posts: 7
    edited February 2020

    Thank you, I can view the bug now.

    Is there an estimated release date for a fix? This is a blocking issue for me.

    Thanks in advance.

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited February 2020

    The bug has been fixed. The only question now is whether the fix has made the deadline to be included with the 19.7 patch release. If not, it will be in 19.8.

    May I ask why you need the fix quickly? The bug can be annoying, but is easy to workaround temporarily by changing the user's privileges to other schemas or renaming the table or column name.

    3818723
  • 3818723
    3818723 Member Posts: 7
    edited February 2020

    I work in a brownfield project, renaming tables is not an option.

    I tried to change the user privileges but was not able to get it working. Could you provide me with an example? Thanks a lot!

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited February 2020

    The earlier reply from user, 4180700, provides an example.

    Basically, you want to remove the read privilege from the other schema with the same table and column name. The quickest way to ensure that is to allow your user to only access its own schema objects and no one else's.

  • 3818723
    3818723 Member Posts: 7
    edited March 2020

    Is there an ETA for 19.7 or 19.8?

  • Alex Keh-Oracle
    Alex Keh-Oracle Posts: 2,751 Employee
    edited March 2020

    19.7 is planned for April. 19.8 is three months after that. These are quarterly patches, so the cadence is every three months.

Sign In or Register to comment.