简体   繁体   English

asp.net core 6 EF脚手架与Oracle数据库

[英]asp.net core 6 EF scaffolding with Oracle database

I am creating Asp.net core 6 web api with oracle 19 as backend.我正在使用 oracle 19 作为后端创建 Asp.net core 6 web api。 i am using DB first approach and create model object from DB table.我正在使用数据库优先方法并从数据库表创建模型对象。 i used the below syntax,我使用了以下语法,

 scaffold-dbcontext "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=TestDB.Test.com)(PORT=1717))(CONNECT_DATA=(SERVICE_NAME=TestDB)));User Id=usename;Password=password;Persist Security Info=True;Connection Lifetime=100000;" Oracle.EntityFrameworkCore -o ModelFolder -f  

Note: i removed the secured data and gave dummy data on the above code.注意:我删除了安全数据并在上面的代码中提供了虚拟数据。 I was able to generate the model from my backend.我能够从我的后端生成模型。 but having some issues with DB type.但是数据库类型有一些问题。 i am trying to call the EF query to get the data and facing cast issue.我正在尝试调用 EF 查询来获取数据并面临转换问题。 one of the table column is datatype is Number(3) and model got created as Byte?.表列之一是数据类型是 Number(3) 并且模型创建为 Byte?。 when it try to bind the entity result, it gives me specified cast is not valid.当它尝试绑定实体结果时,它给我指定的强制转换无效。 its expecting Int.它期待诠释。 am not sure how to solve the issue.我不确定如何解决这个问题。 i should not be modified the auto generated model property to int.我不应该将自动生成的模型属性修改为 int。 not sure is this ongoing issue with asp.net core with oracle.不确定 asp.net core 与 oracle 是否存在这个持续存在的问题。 requesting any suggestion to solve this error.请求解决此错误的任何建议。

I am trying to call the EF query to get the data and facing cast issue.我正在尝试调用 EF 查询来获取数据并面临转换问题。 one of the table column is datatype is Number(3) and model got created as Byte?.表列之一是数据类型是 Number(3) 并且模型创建为 Byte?。 when it try to bind the entity result, it gives me "specified cast is not valid "当它尝试绑定实体结果时,它给我"specified cast is not valid

It would be nicer, if you could add your database entity schema defination and the asp.net core POCO Class .如果您可以添加数据库实体架构定义和asp.net core POCO Class ,那就更好了。 Thus, based on the error, you should consider following data types which usually treated as inconsistent within Oracle to Asp.net core entity scaffolding while generate automatically.因此,基于错误,您应该考虑以下data types ,这些数据类型通常在Oracle中被视为与Asp.net core实体脚手架不一致,同时自动生成。

Please Cheeck Following data type:请检查以下数据类型:

byte? should be long in asp.net core,在 asp.net core 中应该很long

short? should be int应该是int

bool? should be changed to int if it contains number like 0 or 1 other than oracle number should be deal with decimal如果它包含01之类的数字,则应将其更改为int而不是oracle number应处理decimal

Note: When we encounter "specified cast is not valid " it convery the meaning, POCO Class and data entity model error mostly related to defination of asp.net core POCO class which doesn't matached with the database entity defination .注意:当我们遇到"specified cast is not valid ”时,它的意思是, POCO Class and data entity model error mostly related to definition of asp.net core POCO class which doesn't matched with the database entity defination You could follow this official Chart for reference:您可以按照此官方图表进行参考:

在此处输入图像描述

在此处输入图像描述

More details can be founded at official document here可以在official document here中找到更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP.NET MVC Core / 6:EF 6脚手架错误 - ASP.NET MVC Core/6: EF 6 scaffolding error 如何使用 EF Core 更新 ASP.NET 5 中的 dbcontext 脚手架? - How to update dbcontext scaffolding in ASP.NET 5 with EF Core? Asp.net 5和EF7现有的Azure数据库脚手架 - Asp.net 5 and EF7 existing Azure database scaffolding 带有 Oracle 自治数据库的 EF Core 脚手架 - EF Core Scaffolding with Oracle Autonomous Database asp.net 核心 3.1 EF ConcurrencyCheck 无法使用剃刀 CRUD 脚手架而不是 MVC - asp.net core 3.1 EF ConcurrencyCheck not working using razor CRUD scaffolding not MVC 使用 EF Core 搭建 Oracle 数据库的脚手架失败并出现登录被拒绝错误 - Scaffolding an Oracle database with EF Core failing with logon denied error 首先从数据库过滤器记录中使用EF Code的asp.net Webforms支架 - asp.net webforms scaffolding with EF Code first from database filter records ASP.NET Core和EF应用程序在初始化数据库上下文时停止 - ASP.NET Core and EF application stops at initialising Database context ASP.NET 核心实体框架代码到数据库脚手架无法识别 Id 属性或 [Key] 注释 - ASP.NET Core Entity Framework code-to-database scaffolding not recognizing Id property or [Key] annotation ASP.NET Core脚手架错误VS 2017 - ASP.NET Core Scaffolding Error VS 2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM