帮帮我,要求是我需要与 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/