c# - 需要以 C# 字符串数据类型 "as is"获取 Oracle RAW

标签 c# oracle entity-framework-6

帮帮我,要求是我需要与 C# 中的 Oracle RAW 相同的值作为字符串。我能够将字符串保存为oracle表中的RAW值,但是在获取它时给出 异常“对象必须实现 IConvertible”

我可以理解,由于 RAW 数据类型未映射到任何主要数据类型,因此编译器给出了此异常,但是我怎样才能实现这一点?

我使用 EF6 代码优先方法,在后端我使用 Oracle 12C,

下面是示例代码,

 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");
        }
    }

最佳答案

RAW 数据类型为 documented如:

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.

换句话说,它是 byte[]string 更好的映射。转换为字符串需要应用编码。

我建议您尝试将列映射到byte[],然后在.NET 中使用适当的编码将其转换为字符串。 (例如Encoding.UTF8.GetString(bytes)。)

关于c# - 需要以 C# 字符串数据类型 "as is"获取 Oracle RAW,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30911283/

相关文章:

c# - 人们如何使用 Entity Framework 6 进行单元测试,你应该打扰吗?

c# - 外键列可以首先是 Entity Framework 6 代码中的枚举吗?

c# - 关于将实体映射到域对象的建议

C# volatile double

c# - 在 NULL 的 LINQ 查询中将字符串设置为 ""

java - JDBC 事务死锁 : solution required?

c# - MySQL 中带有波兰语字符的 AES_DECRYPT() 和 AES_ENCRYPT()

SQL 不是带有 OracleSQL 和 InnerQuery 错误的 GROUP BY 表达式

sql - 找出每学期和每门类(class)中得分最高的学生的名字?

c# - DbContext 全局范围与方法级范围