• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

Question How do I map oracle UDT to C# custom type

dzenesiz

New member
Joined
Apr 3, 2017
Messages
1
Programming Experience
1-3
I am trying to map a simple Oracle UDT in my c# application. When I try to extract data from DataReader, it throws the following exception:

Custom type mapping for 'dataSource='DB' schemaName='C##USER' typeName='MATICNIBROJ_T'' is not specified or is invalid

My Oracle UDT is:

Code:
create or replace 
TYPE            "MATICNIBROJ_T" AS OBJECT (
  MaticniBroj NUMBER(13)
)
INSTANTIABLE NOT FINAL
Custom class used for mapping:

Code:
public class MaticniBrojT : IOracleCustomType
    {
        [OracleObjectMappingAttribute("MaticniBroj")]
        public virtual int MaticniBroj { get; set; }

        //c# custom type --> Oracle UDT
        public virtual void FromCustomObject(OracleConnection conn, IntPtr obj)
        {
            OracleUdt.SetValue(conn, obj, "MaticniBroj", this.MaticniBroj);
        }

        //Oracle UDT --> c# custom type
        public virtual void ToCustomObject(OracleConnection conn, IntPtr obj)
        {
            this.MaticniBroj = ((int)(OracleUdt.GetValue(conn, obj, "MaticniBroj")));
        }
    }
DB communication:

Code:
string upit = @"SELECT PIB, NAZIV, RACUN, FAX, TELEFON, ADRESA, EMAIL,
    MATICNIBR FROM KOMITENT_VW k WHERE UPPER(NAZIV) LIKE '%" + naziv.ToUpper() + "%'";

                    conn = napraviKonekciju();

                    conn.Open();

                OracleCommand cmd = new OracleCommand();

                cmd.Connection = conn;

                cmd.CommandText = upit;
                cmd.CommandType = CommandType.Text;

                OracleDataReader dr = cmd.ExecuteReader();

                DataSet ds = new DataSet();
                DataTable dt = new DataTable();

                dt.Columns.Add("PIB");
                dt.Columns.Add("NAZIV");
                dt.Columns.Add("RACUN");
                dt.Columns.Add("FAX");
                dt.Columns.Add("TELEFON");
                dt.Columns.Add("ADRESA");
                dt.Columns.Add("EMAIL");
                dt.Columns.Add("MATICNIBR");
                ds.Tables.Add(dt);

                while(dr.Read())
                {
                    DataRow red = dt.NewRow();
                    red["PIB"] = dr.GetInt32(0);
                    red["NAZIV"] = dr.GetString(1);
                    red["RACUN"] = dr.GetString(2);
                    red["FAX"] = dr.GetString(3);
                    red["TELEFON"] = dr.GetString(4);
                    red["ADRESA"] = dr.GetString(5);
                    red["EMAIL"] = dr.GetString(6);
                    //----next line throws an exception
                    MaticniBrojT mBroj = (MaticniBrojT)dr.GetValue(7);

                    red["MATICNIBR"] = Convert.ToInt64(mBroj.MaticniBroj);
                }

                return ds;
            }
            catch (Exception ex)
            {
                return null;
            }
            finally
            {
                conn.Close();
                conn.Dispose();
                conn = null;
            }
Any suggestions?
 
Top Bottom