Oracle RAW(16)使用ObjectContext ExecuteStoreQuery作为byte []返回 [英] Oracle RAW(16) returned as byte[] with ObjectContext ExecuteStoreQuery

查看:49
本文介绍了Oracle RAW(16)使用ObjectContext ExecuteStoreQuery作为byte []返回的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象模型,其中C#Guids映射到RAW(16)Oracle Fields。



我尝试使用ObjectContext ExecuteStoreQuery方法执行SELECT查询但是它返回错误:
$


System.Data.Entity.dll中出现"System.InvalidOperationException"类型的异常但未在用户代码中处理

附加信息:'新闻'上的'dbNewsID'属性无法设置为'Byte []'值。您必须将此属性设置为'Guid'类型的非空值。



代码如下:



新闻新闻= Context.ExecuteStoreQuery< News>(@" select uidnews"" dbNewsID"",codnews"" dbNewsCode"",destitle"" dbTitleDescription"" from NewsTable,其中
rownum = 1")。ToList()。FirstOrDefault();



其中新闻是C#类,dbNewsID是Guid,而NewsTable是Oracle表,其中uidnews是RAW(16)主键。



是否可以执行这个查询没有改变Guid映射?



PS:我用提供者连接到Oracle Oracle.ManagedDataAccess.Client



谢谢,

Sandro



Hi, I have an object model with C# Guids mapped to RAW(16) Oracle Fields.

I try to execute a SELECT query with ObjectContext ExecuteStoreQuery method but it returns the errore:

An exception of type 'System.InvalidOperationException' occurred in System.Data.Entity.dll but was not handled in user code
Additional information: The 'dbNewsID' property on 'News' could not be set to a 'Byte[]' value. You must set this property to a non-null value of type 'Guid'.

The code is like following:

News news = Context.ExecuteStoreQuery<News>(@"select uidnews ""dbNewsID"", codnews ""dbNewsCode"", destitle ""dbTitleDescription"" from NewsTable where rownum = 1").ToList().FirstOrDefault();

Where News is the C# class were dbNewsID is a Guid and NewsTable is the Oracle Table where uidnews is a RAW(16) primary key.

Is it possible to execute this query without changing the Guid mapping?

PS: I'm connecting to Oracle with provider Oracle.ManagedDataAccess.Client

Thanks,
Sandro


推荐答案

你可以为uidnews添加一个byte []字段,然后为 创建一个Guid属性。 dbNewsID获取并设置它的值。

You can probably add a byte[] field for uidnews, then create a Guid property for dbNewsID getting and setting value for it.

修改你的TT模板,使其生成"部分"模板。而不是实体的类。

Modify your TT template so it generates "partial" class for the entities instead.

如下所示:

    public partial class News
    {
        public Guid dbNewsID
        {
            get { return new Guid(this.uidnews); }
            set { this.uidnews = value.ToByteArray(); }
        }
    }


这篇关于Oracle RAW(16)使用ObjectContext ExecuteStoreQuery作为byte []返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆