I am trying to scaffoled the db context of one specific table in an existing oracle db.
dotnet ef dbcontext scaffold 'data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=some.remote.hostname)(PORT=1337))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SVC_NAME)));user id=USER;password=PASS' Oracle.EntityFrameworkCore --table TABLE_NAME --schema SCHEMA_NAME --use-database-names -f
The CLI then prints
Build started...
Build succeeded.
Followed by by a whole lot of warning messages of the following type. None of the tables mentioned in that warnings has anything to do with my table I want to scaffold.
Unable to identify the primary key for table 'SCHEMA_NAME.SOME_OTHER_TABLE_NAME'.
Unable to generate entity type for table 'SCHEMA_NAME.SOME_OTHER_TABLE_NAME'.
After some time there is an exception thrown
System.InvalidOperationException: The types of the properties specified for the foreign key {'SOME_COLUMN'} on entity type 'SOME_TABLE' do not match the types of the properties in the principal key {'SOME_OTHER_COLUMN'} on entity type 'SOME_TABLE'.
at Microsoft.EntityFrameworkCore.Metadata.Internal.ForeignKey.AreCompatible(IReadOnlyList`1 principalProperties, IReadOnlyList`1 dependentProperties, EntityType principalEntityType, EntityType dependentEntityType, Boolean shouldThrow)
at Microsoft.EntityFrameworkCore.Metadata.Internal.ForeignKey.AreCompatible(EntityType principalEntityType, EntityType dependentEntityType, MemberInfo navigationToPrincipal, MemberInfo navigationToDependent, IReadOnlyList`1 dependentProperties, IReadOnlyList`1 principalProperties, Nullable`1 unique, Nullable`1 required, Boolean shouldThrow)
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.AddForeignKey(IReadOnlyList`1 properties, Key principalKey, EntityType principalEntityType, Nullable`1 configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.Microsoft.EntityFrameworkCore.Metadata.IMutableEntityType.AddForeignKey(IReadOnlyList`1 properties, IMutableKey principalKey, IMutableEntityType principalEntityType)
at Microsoft.EntityFrameworkCore.MutableEntityTypeExtensions.GetOrAddForeignKey(IMutableEntityType entityType, IReadOnlyList`1 properties, IMutableKey principalKey, IMutableEntityType principalEntityType)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitForeignKey(ModelBuilder modelBuilder, DatabaseForeignKey foreignKey)
at Microsoft.EntityFrameworkCore.Scaffolding.Internal.RelationalScaffoldingModelFactory.VisitForeignKeys(ModelBuilder modelBuilder, IList`1 foreignKeys) 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 types of the properties specified for the foreign key {'SOME_COLUMN'} on entity type 'SOME_TABLE' do not match the types of the properties in the principal key {'SOME_OTHER_COLUMN'} on entity type 'SOME_TABLE'.
It appears my scaffold command actually ignores the --table option and looks at the whole database. Where apparently there is some misconfiguration, on which I have no influence on.
Is there a way around this? Can I manually scaffold a table?
Cheers
I found a way around this problem removing the schema parameter from the scaffold command and passing the schema directly on the table name parameter
dotnet ef dbcontext scaffold 'data source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=some.remote.hostname)(PORT=1337))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=SVC_NAME)));user id=USER;password=PASS' Oracle.EntityFrameworkCore --table SCHEMA.TABLE_NAME --use-database-names -f
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With