我有存储过程,它接受表类型作为输入参数。 如何从C#代码传递对象?将表类型对象作为输入参数传递给Oracle中的存储过程C#
create or replace TYPE CUSTOM_TYPE AS OBJECT
(
attribute1 VARCHAR(10),
attribute2 VARCHAR(10)
);
create or replace TYPE CUSTOM_TYPE_ARRAY AS TABLE OF CUSTOM_TYPE;
PROCEDURE SP_TEST
(
P_TABLE_IN IN CUSTOM_TYPE_ARRAY,
P_RESULT_OUT OUT SYS_REFCURSOR
) AS
BEGIN
OPEN P_RESULT_OUT FOR
SELECT ti.attribute1, ti.attribute2, ti.attribute3
FROM TABLE(P_TABLE_IN) ea inner join MYTABLE ti on ea.attribute1 = ti.attribute1 and ea.attribute2 = ti.attribute2;
END SP_TEST;
,并试图添加参数是这样的:
var oracleParam = new OracleParameter();
oracleParam.OracleDbType = OracleDbType.Array;
oracleParam.Direction = ParameterDirection.Input;
oracleParam.ParameterName = "P_TABLE_IN";
oracleParam.Value = entities;
oracleCommand.Parameters.Add(oracleParam);
如果实体是实体的自定义集合的一个实例(与定义甲骨文属性映射)
public class EntityUdt
{
[OracleObjectMappingAttribute("attribute1")]
public string attribute1 {get;set;}
[OracleObjectMappingAttribute("attribute2")]
public string attribute2 {get;set;}
}
我跟着this guide到正确定义.net实体,但通过我的列表仍然没有运气:
System.InvalidOperationException了由用户代码未处理
的HResult = -2146233079
消息= 'EntityUdt :: ATTRIBUTE1 :: OracleObjectMappingAttribute' 不能被设置为 'ATTRIBUTE1'
源= Oracle.DataAccess栈跟踪的无效值: 在Oracle.DataAccess.Types.OracleUdtDescriptor.DescribeCustomType(对象 customTypeFactory)
Alexey - 你能提供完整的SP_TEST定义吗?我有兴趣了解如何创建并返回结果集? – jasonnissen 2014-11-06 02:42:27