EF + ODP.NET + CLOB = 值不能为 Null - 参数名称:byteArray?

EF + ODP.NET + CLOB = Value Cannot be Null - Parameter name: byteArray?(EF + ODP.NET + CLOB = 值不能为 Null - 参数名称:byteArray?)

本文介绍了EF + ODP.NET + CLOB = 值不能为 Null - 参数名称:byteArray?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的项目最近更新到较新的 Oracle.ManagedDataAccess DLL (v 4.121.2.0),并且此错误一直在间歇性地出现.我们已经修复了几次,但并不真正知道我们做了什么来修复它.

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.

我相当肯定这是由于 CLOB 字段被映射到实体框架中的字符串,然后在 LINQ 语句中被选中,从而拉动整个实体,而不仅仅是一组有限的属性.

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.

错误:

Value cannot be null.
Parameter name: byteArray

堆栈跟踪:

   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()

可疑实体属性:

'Mapped to Oracle CLOB Column'
<Column("LARGEFIELD")>
Public Property LargeField As String

但我相信这是映射每个 Oracle 矩阵的字段的正确方法:

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

ODP.NET 类型概述

生成的 SQL 语句也没有明显错误:

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

SELECT 
...
"Extent1"."LARGEFIELD" AS "LARGEFIELD",
...
FROM ... "Extent1"
WHERE ...

我也按照 Ozkan 的建议尝试了这个 Fluent 代码,但它似乎不影响我的情况.

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()

疑难解答更新:

经过大量测试,我们非常确定这实际上是一个错误,而不是配置问题.在一组非常特定的情况下,导致问题的似乎是 CLOB 的内容.我已在 Oracle 论坛 上交叉发布此内容,希望更多信息.

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.

推荐答案

安装Oracle12客户端后遇到同样的问题.在 machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) 中,我使用 Oracle.ManagedDataAccess 删除了所有条目.在目录 C:WindowsMicrosoft.NETassemblyGAC_MSIL 中,我删除了 Oracle.ManagedDataAccess 和 Policy.4.121.Oracle.ManagedDataAccess.然后我的 C# 程序开始正常工作,使用它自己目录中的 Oracle.ManagedDataAccess dll.

After installation of Oracle12 client we ran into the same problem. In machine.config (C:WindowsMicrosoft.NETFrameworkv4.0.30319Config) I removed all entries with Oracle.ManagedDataAccess. In directory C:WindowsMicrosoft.NETassemblyGAC_MSIL I removed both Oracle.ManagedDataAccess and Policy.4.121.Oracle.ManagedDataAccess. Then my C# program started working as usually, using the Oracle.ManagedDataAccess dll in it's own directory.

这篇关于EF + ODP.NET + CLOB = 值不能为 Null - 参数名称:byteArray?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:EF + ODP.NET + CLOB = 值不能为 Null - 参数名称:byteArray?

基础教程推荐