【问题标题】:Scaffold dbcontext of specific table from oracle database throws error unrelated to that tableoracle数据库中特定表的脚手架dbcontext抛出与该表无关的错误
【发布时间】:2020-01-16 14:05:20
【问题描述】:

我正在尝试在现有的 oracle 数据库中搭建一个特定表的数据库上下文。

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.

随后是以下类型的大量警告消息。该警告中提到的所有表格都与我要搭建的表格无关。

无法识别表“SCHEMA_NAME.SOME_OTHER_TABLE_NAME”的主键。

无法为表“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 选项并查看整个数据库。显然有一些错误配置,我对此没有影响。

有没有办法解决这个问题?我可以手动搭建表格吗?

干杯

【问题讨论】:

  • 检查是否找到了解决方案?
  • Tbh,我再也没有追求它并放弃了。很可能是因为我明显不喜欢 Oracle。

标签: oracle ef-core-2.1 .net-core-3.1


【解决方案1】:

我找到了解决这个问题的方法,从脚手架命令中删除架构参数并直接在表名参数上传递架构

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 1970-01-01
    • 2022-10-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多