来自用户定义类型的不支持的列数据类型
Unsupported column datatype from the user-defined type
我不知道我错过了什么让 ManagedDataAccess 抱怨 "Unsupported column datatype"。我喜欢这个错误没有指出是什么类型或什么 "column" 给它带来了痛苦。有人可以查看下面的代码并让我知道我错过了什么吗?非常感谢!
table
CREATE TABLE "PORTAL_OPS"."SHAPE"
(
"SIDES" NUMBER(1,0) NOT NULL ENABLE
)
类型
create or replace type shapeudt as object
(
sides number(1,0)
)
class
[OracleCustomTypeMappingAttribute("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMappingAttribute("SIDES")]
public Int32 sides;
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "SIDES", sides);
}
public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
sides = (int)OracleUdt.GetValue(con, pUdt, "SIDES");
}
public IOracleCustomType CreateObject()
{
return new Shape();
}
}
调用 UDT 到过程:
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
//param.UdtTypeName = udt.DatabaseTypeName;
param.DbType = DbType.Object;
// this needs to stay at the end...if you move it ahead of the
// previous line, you will get
// "Value does not fall within the expected range" error
param.Value = udt;
Command.CommandText = "portal_ops.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
Command.ExecuteNonQuery();
Command.Dispose();
Command.Connection.Close();
解决了!
原因:
没有使用正确的 OracleDbType。对于 UDT,您必须在定义 OracleParameter 时使用 OracleDbType.Object。如果您像我一样,想成为 Oracle Managed Driver 的粉丝。好吧,你是 SOL,因为从 19.6 版本开始,Oracle Managed Data Access Nuget 仍然不支持 OracleDbType.Object.
解法:
切换到非托管驱动程序。是的,您必须与托管驱动程序分手。
从 here 下载 VS 工具。是的,问题是您必须使用 Oracle Universal Installer (OUI) 安装的那个。
我不知道我错过了什么让 ManagedDataAccess 抱怨 "Unsupported column datatype"。我喜欢这个错误没有指出是什么类型或什么 "column" 给它带来了痛苦。有人可以查看下面的代码并让我知道我错过了什么吗?非常感谢!
table
CREATE TABLE "PORTAL_OPS"."SHAPE"
(
"SIDES" NUMBER(1,0) NOT NULL ENABLE
)
类型
create or replace type shapeudt as object
(
sides number(1,0)
)
class
[OracleCustomTypeMappingAttribute("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMappingAttribute("SIDES")]
public Int32 sides;
public void FromCustomObject(OracleConnection con, IntPtr pUdt)
{
OracleUdt.SetValue(con, pUdt, "SIDES", sides);
}
public void ToCustomObject(OracleConnection con, IntPtr pUdt)
{
sides = (int)OracleUdt.GetValue(con, pUdt, "SIDES");
}
public IOracleCustomType CreateObject()
{
return new Shape();
}
}
调用 UDT 到过程:
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
//param.UdtTypeName = udt.DatabaseTypeName;
param.DbType = DbType.Object;
// this needs to stay at the end...if you move it ahead of the
// previous line, you will get
// "Value does not fall within the expected range" error
param.Value = udt;
Command.CommandText = "portal_ops.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
Command.ExecuteNonQuery();
Command.Dispose();
Command.Connection.Close();
解决了!
原因: 没有使用正确的 OracleDbType。对于 UDT,您必须在定义 OracleParameter 时使用 OracleDbType.Object。如果您像我一样,想成为 Oracle Managed Driver 的粉丝。好吧,你是 SOL,因为从 19.6 版本开始,Oracle Managed Data Access Nuget 仍然不支持 OracleDbType.Object.
解法: 切换到非托管驱动程序。是的,您必须与托管驱动程序分手。 从 here 下载 VS 工具。是的,问题是您必须使用 Oracle Universal Installer (OUI) 安装的那个。