[英]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
如果它包含
0
或1
之类的数字,则应将其更改为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.