需求:最近在新开发一套在LINUX运行的API接口,需要用到net core api框架以及oracle数据库,首先需要解决的就是连接数据库问题,由于是DBFirst 加上之前很多老表不规范,导致了core EF生成模型报错。正在解决。

net core版本: 2.2

依赖库:

Microsoft.EntityFrameworkCore 2.2.6
Oracle.EntityFrameworkCore 2.2.6
Microsoft.EntityFrameworkCore.Tools 2.2.6
Microsoft.VisualStudio.Web.CodeGeneration.Design 2.2.4

在VS2019控制台通过以下语句生成数据库模型

 Scaffold-DbContext "DATA SOURCE=地址:1521/zmbx;PASSWORD=密码;PERSIST SECURITY INFO=True;USER ID=XXX;Validate Connection = true;" Oracle.EntityFrameworkCore -OutputDir Models -Project DBLib -Force

采用-Tables USERMOBILE 去生成表模型,可以生成 。 但是多个表生成就会有问题。根据提示信息表示可能是存在主键为空。有没有办法跳过为空的继续生成?

错误如下

The column 'xxx.xxx.ISCREATEPLAN' would normally be mapped to a non-nullable bool property, but it has a default constraint. Such a column is mapped to a nullable bool property to 
allow a difference between setting the property to false and invoking the default constraint. See https://go.microsoft.com/fwlink/?linkid=851278 for details.
Unable to identify the primary key for table 'xxx.xxx'.
Unable to generate entity type for table 'xxx.xxx'.
System.InvalidOperationException: The property list {'UserId', 'UserId'} cannot be used, because it contains a duplicate - 'UserId'.
at Microsoft.EntityFrameworkCore.Metadata.Internal.EntityType.AddKey(IReadOnlyList` properties, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.HasKeyInternal(IReadOnlyList` properties, Nullable` configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.PrimaryKey(IReadOnlyList` properties, ConfigurationSource configurationSource)
at Microsoft.EntityFrameworkCore.Metadata.Internal.InternalEntityTypeBuilder.PrimaryKey(IReadOnlyList` propertyNames, 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` 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` tables, IEnumerable` 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` schemas, IEnumerable` tables, Boolean useDataAnnotations, Boolean overwriteFiles, Boolean useDatabaseNames)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.ScaffoldContextImpl(String provider, String connectionString, String outputDir, String outputDbContextDir, String dbContextClassName, IEnumerable` schemaFilters, IEnumerable` 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`.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
The property list {'UserId', 'UserId'} cannot be used, because it contains a duplicate - 'UserId'.

CORE EF生成ORACLE数据库模型报错问题记录的更多相关文章

  1. Oracle启动报错ORA-27102解决

    环境:RHEL5.5 + Oracle 10.2.0.4 此错误一般是因为数据库的初始化参数文件的内存设置不当导致.本例是因为操作系统参数设置问题导致. 当前现象:Oracle启动报错ORA-2710 ...

  2. windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help

    windows 8 安装 oracle 11g 报错:command line option syntax error,type command/? for help 在windows8操作系统上安装 ...

  3. EF core2.1+MySQL报错'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)

    一.使用.net core 2.0 EF mysql 运行一直报错如下: An unhandled exception occurred while processing the request. M ...

  4. oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT

    oracle之报错:ORA-00054: 资源正忙,要求指定 NOWAIT 问题如下: SQL> conn scott/tiger@vm_database Connected to Oracle ...

  5. oracle dg 报错提示 涉及硬盘错误

    ###oracle dg 报错提示 涉及硬盘错误 Dec 23 03:28:01 xhisdg rsyslogd: [origin software="rsyslogd" swVe ...

  6. 【python-HTMLTestRunner】生成HTMLTestRunner报告报错ERROR 'ascii' codec can't decode byte 0xe5 in position 0: ordinal not in range(128)

    [python-HTMLTestRunner]生成HTMLTestRunner报告报错:ERROR 'ascii' codec can't decode byte 0xe5 in position 0 ...

  7. TNS-12532: TNS:invalid argument,Oracle的报错信息太让人无语

    TNS-12532: TNS:invalid argument,Oracle的报错信息太让人无语 现象: Tnsping报错: [oracle@unicomGZ01 admin]$ ../../bin ...

  8. oracle 12c 报错 ora-03137 来自客户机的格式错误的TTC包被拒绝

    昨天下午,实施报了一个oracle的报错ora-03137 说是数据库在11g时没有问题,升级到12c 时,就报错了. 本地调试,看到执行完sql后,报异常,如下: 把SqL在12c的数据库执行一下, ...

  9. Oracle数据库报错: ORA-29275:部分多字节字符

    Oracle数据库报错: ORA-29275:部分多字节字符 就是你查出来的字符串(有汉字的)有可能会出问题, 在认为有问题的字段 用 to_nchar("字段")包起来 比如 你 ...

随机推荐

  1. 如何在CentOS 7上安装Memcached(缓存服务器)

    首先更新本地软件包索引,然后使用以下yum命令从官方CentOS存储库安装Memcached. yum update yum install memcached 接下来,我们将安装libmemcach ...

  2. centos中screen的使用

    只是讲解几个简单的操作,例如,创建新窗口,切换到新窗口,删除窗口.(因为我要启动elk,所以需要使用到screen) 一.创建一个新窗口: 安装完成后,直接敲命令screen就可以启动它.但是这样启动 ...

  3. springboot之kafka安装与实践

    环境:腾讯云centos7 1.下载 http://mirror.bit.edu.cn/apache/kafka/2.3.0/kafka_2.11-2.3.0.tgz 2.解压 tar -xvf ka ...

  4. Cinder LVM Oversubscription in thin provisioning

    目录 文章目录 目录 Oversubscription in thin provisioning Oversubscription in thin provisioning Cinder spec: ...

  5. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_01-页面静态化需求分析

    上半部分就是静态化 业务流程如下: 1.获取模型数据 2.制作模板 3.对页面进行静态化 4.将静态化生成的html页面存放文件系统中 5.将存放在文件系统的html文件发布到服务器

  6. 搭建无人值守安装服务器(CentOS)

    使用PXE+DHCP+TFTP+Kickstart+FTP搭建无人值守安装服务器.一般只有频繁安装系统才会搭建无人值守安装服务器. 虚拟机环境:youxi1,CentOS7系统双网卡,一个网卡桥接模式 ...

  7. OpenLDAP管理命令详解

    一.OpenLDAP命令汇总 ldapsearch:搜索 OpenLDAP 目录树条目. ldapadd:通过 LDIF 格式,添加目录树条目. ldapdelete:删除 OpenLDAP 目录树条 ...

  8. MSMQ菜鸟教程

    一  .MSMQ概述 MSMQ全称MicroSoft Message Queue,微软消息队列,是在多个不同的应用之间实现相互通信的一种异步传输模式,相互通信的应用可以分布于同一台机器上,也可以分布于 ...

  9. 12-1 TCP/IP协议栈

    TCP/IP协议栈 有限状态机FSM:Finite State Machine CLOSED 没有任何连接状态 LISTEN 侦听状态,等待来自远方TCP端口的连接请求 SYN-SENT 在发送连接请 ...

  10. python-Web-flask-视图内容和模板

    2 视图内容和模板: 基本使用 #设置cookie值 @app.route('/set_cookie') def set_cookie(): response = make_response(&quo ...