Need to fetch Oracle RAW in C# string datatype "as is"

Help me out, requirement is that I need the same value of Oracle RAW to be in C# as a string. I am able to save String as RAW value in oracle table, but while fetching it is giving exception "Object must implement IConvertible"

which I can understand that since RAW data type is not mapped to any primary data type so complier is giving this exception, But How can I achieve this?

I am using EF6 code first approach, in backend I am using Oracle 12C,

Below is the sample code,

 public partial class EF6TEST
{
    [Key]
    [Column(Order = 0)]
   // [MaxLength(32)]
    public string ID { get; set; }

    [Key]
    [Column(Order = 1)]
    [StringLength(50)]
    public string NAME { get; set; }
}
 public class BE
{
    public string id;
    public string name;
}


class Program
{
    static void Main(string[] args)
    {
        List<BE> be;
        try
        {
            using (var context = new Model1())
            {
                #region insert
                context.EF6TEST.Add(new EF6TEST()
                {
                    ID = "96A8B17B17FB464B886146A28399E7E2",
                    NAME = "NewRAM"
                });
                #endregion
                context.SaveChanges();

                #region fetch
                be = (from t in context.EF6TEST
                      select new BE
                      {
                          id = t.ID,
                          name = t.NAME
                      }).ToList<BE>();


                #endregion                                       

            }
            Console.ReadKey();
        }
        catch (Exception ex)
        {
            Console.WriteLine("Exception found");
        }
    }
Jon Skeet
people
quotationmark

The RAW datatype is documented as:

The RAW and LONG RAW datatypes are used for data that is not to be interpreted (not converted when moving data between different systems) by Oracle Database. These datatypes are intended for binary data or byte strings.

In other words, it's a better mapping for byte[] than string. Converting to a string requires an encoding to be applied.

I suggest you try mapping your column to byte[] instead, and then convert it to a string using an appropriate encoding within .NET. (e.g. Encoding.UTF8.GetString(bytes).)

people

See more on this question at Stackoverflow