存clob为空的值_EF + ODP.NET + CLOB =值不能为空 - 参数名称:byteArray?

Our project recently updated to the newer Oracle.ManagedDataAccess DLL's (v 4.121.2.0) and this error has been cropping up intermittently. We've fixed it a few times without really knowing what we did to fix it.

I'm fairly certain it's caused by CLOB fields being mapped to strings in Entity Framework, and then being selected in LINQ statements that pull entire entities instead of just a limited set of properties.

Error:

Value cannot be null.

Parameter name: byteArray

Stack Trace:

at System.BitConverter.ToString(Byte[] value, Int32 startIndex, Int32 length)

at OracleInternal.TTC.TTCLob.GetLobIdString(Byte[] lobLocator)

at OracleInternal.ServiceObjects.OracleDataReaderImpl.CollectTempLOBsToBeFreed(Int32 rowNumber)

at Oracle.ManagedDataAccess.Client.OracleDataReader.ProcessAnyTempLOBs(Int32 rowNumber)

at Oracle.ManagedDataAccess.Client.OracleDataReader.Read()

at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.StoreRead()

Suspect Entity Properties:

'Mapped to Oracle CLOB Column'

Public Property LargeField As String

But I'm confident this is the proper way to map the fields per Oracle's matrix:

There is nothing obviously wrong with the generated SQL statement either:

SELECT

...

"Extent1"."LARGEFIELD" AS "LARGEFIELD",

...

FROM ... "Extent1"

WHERE ...

I have also tried this Fluent code per Ozkan's suggestion, but it does not seem to affect my case.

modelBuilder.Entity(Of [CLASS])().Property(

Function(x) x.LargeField

).IsOptional()

Troubleshooting Update:

After extensive testing, we are quite certain this is actually a bug, not a configuration problem. It appears to be the contents of the CLOB that cause the problem under a very specific set of circumstances. I've cross-posted this on the Oracle Forums, hoping for more information.

解决方案

We have this problem as well on some computers, and we are running the latest Oracle.ManagedDataAccess.dll (4.121.2.20150926 ODAC RELEASE 4).

We found a solution to our problem, and I just wanted to share.

This was our problem that occurred some computers.

Using connection As New OracleConnection(yourConnectionString)

Dim command As New OracleCommand(yourQuery, connection)

connection.Open()

Using reader As OracleDataReader = command.ExecuteReader()

Dim clobField As String = CStr(reader.Item("CLOB_FIELD"))

End Using

connection.Close()

End Using

And here's the solution that made it work on all computers.

Using connection As New OracleConnection(yourConnectionString)

Dim command As New OracleCommand(yourQuery, connection)

connection.Open()

Using reader As OracleDataReader = command.ExecuteReader()

Dim clobField As String = reader.GetOracleClob(0).Value

End Using

connection.Close()

End Using

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值