来自 Oracle 数据库的特定 table 的脚手架 dbcontext 抛出与 table 无关的错误
Scaffold dbcontext of specific table from oracle database throws error unrelated to that table
我正在尝试在现有的 Oracle 数据库中搭建一个特定 table 的数据库上下文。
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
CLI 然后打印
Build started...
Build succeeded.
随后是大量以下类型的警告消息。警告中提到的 table 中的 None 与我的 table 我想要脚手架有关。
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'.
一段时间后抛出异常
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'.
看来我的脚手架命令实际上忽略了 --table 选项并查看了整个数据库。显然有一些错误配置,我对此没有影响。
有办法解决这个问题吗?我可以手动构建 table 吗?
干杯
我找到了解决此问题的方法,从脚手架命令中删除架构参数并直接在 table 名称参数上传递架构
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
我正在尝试在现有的 Oracle 数据库中搭建一个特定 table 的数据库上下文。
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
CLI 然后打印
Build started...
Build succeeded.
随后是大量以下类型的警告消息。警告中提到的 table 中的 None 与我的 table 我想要脚手架有关。
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'.
一段时间后抛出异常
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'.
看来我的脚手架命令实际上忽略了 --table 选项并查看了整个数据库。显然有一些错误配置,我对此没有影响。
有办法解决这个问题吗?我可以手动构建 table 吗?
干杯
我找到了解决此问题的方法,从脚手架命令中删除架构参数并直接在 table 名称参数上传递架构
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