这是我到 Oracle 中 UDT 的类映射(非常简单):
[OracleCustomTypeMapping("PORTAL_OPS.SHAPEUDT")]
public class Shape : IOracleCustomType, IOracleCustomTypeFactory
{
[OracleObjectMapping("SIDES")]
public Int32 Sides { get; set; }
public string UdtTypeName
{
get
{
Attribute attr = Attribute.GetCustomAttribute(this.GetType()
, typeof(OracleCustomTypeMappingAttribute));
return (attr != null) ?
((OracleCustomTypeMappingAttribute)attr).UdtTypeName
:
String.Empty;
}
}
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();
}
}
调用存储过程:
if (Command.Connection.State == ConnectionState.Closed)
{
Command.Connection.Open();
}
// setting up the parameter
OracleParameter param = new OracleParameter();
param.Direction = ParameterDirection.Input;
param.UdtTypeName = udt.UdtTypeName;
param.DbType = DbType.Object;
param.OracleDbType = OracleDbType.Object;
param.Value = udt;
Command.CommandText = "PORTAL_OPS.PROC_CREATE_SHAPE";
Command.CommandType = CommandType.StoredProcedure;
Command.Parameters.Add(param);
Command.ExecuteNonQuery();
实例化:
Shape shape = new Shape();
shape.sides = 4;
//invoking the stored procedure call (see code above)
我无法弄清楚为什么我不断收到“价值不在预期范围内”。整个周末都在看这个……运气不好。任何帮助是极大的赞赏。