需求:最近在新开发一套在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. 全国计算机等级考试二级教程2019年版——Python语言程序设计参考答案

    第二章 Python语言基本语法元素 一.选择题C B B C A D B A D B二.编程题1.获得用户输入的一个整数N,计算并输出N的32次方.在这里插入图片描述2.获得用户输入的一段文字,将这 ...

  2. v-on绑定特性命名带小横杠 ‘-’与props属性中变量怎么对应

    特性命名问题: 矛盾点一:html的特性不区分大小写 矛盾点二:Vue中除了模板命名,其他命名不允许出现小横杠 ‘-’ 在js文件内,命名为驼峰式,camerCase,进入html文件,自动转换成短横 ...

  3. linux下的什么工具可以用来查看PostScript文件?

    答: ghostview,官网在这里

  4. 在Win7下玩PC游戏发生类似d3d9x_43.dll找不到的情况

    由于d3d9x属于DirectX9.0c扩展,默认不会随系统安装.因此要快速修复这个问题可以去微软官网下载D3D驱动补丁. http://www.microsoft.com/zh-cn/downloa ...

  5. VBA 格式化excel数据表 (数据分列)

    Sub ImportData() ' ' Copy Data from one workbook to the Current Workbook ' Place the macro file in t ...

  6. Spark On YARN启动流程源码分析(一)

    本文主要参考: a. https://www.cnblogs.com/yy3b2007com/p/10934090.html 0. 说明 a. 关于spark源码会不定期的更新与补充 b. 对于spa ...

  7. Flutter dio伪造请求头获取数据

    在很多时候,后端为了安全都会有一些请求头的限制,只有请求头对了,才能正确返回数据.这虽然限制了一些人恶意请求数据,但是对于我们聪明的程序员来说,就是形同虚设.下面就以极客时间为例,讲一下通过伪造请求头 ...

  8. VC程序运行时间测试函数

    VC程序运行时间测试函数 介绍 我们在衡量一个函数运行时间,或者判断一个算法的时间效率,或者在程序中我们需要一个定时器,定时执行一个特定的操作,比如在多媒体中,比如在游戏中等,都会用到时间函数.还比如 ...

  9. Qt——鼠标拖动缩放窗口源码

    #ifndef MOVEWIDGET_H #define MOVEWIDGET_H #include <QWidget> #include <QEvent> class Mov ...

  10. C#实现工作日和休息日(包括法定节假日)的计算

    转自:http://www.cnblogs.com/yuan-chong/p/HolidayHelper.html 一.开发背景: 最近在公司开发的系统中,需要计算工作日,就是给出一个采购周期(n天) ...