gpt4 book ai didi

.net - Azure 上的 Entity Framework "Invalid attempt to read when no data is present"和 'large' 数据

转载 作者:行者123 更新时间:2023-12-03 04:22:03 28 4
gpt4 key购买 nike

我使用 Entity Framework (v4.0) 连接到 SQL Azure(我安装了 March SDK),并在尝试查询表时收到 InvalidOperationException。异常消息是不存在数据时读取无效尝试。并且堆栈跟踪清楚地表明,当 EF 尝试获取列标题时,该操作在内部失败:

at System.Data.SqlClient.SqlDataReader.ReadColumnHeader(Int32 i) 
at System.Data.SqlClient.SqlDataReader.IsDBNull(Int32 i)
at lambda_method(Closure , Shaper )
at System.Data.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
at System.Data.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Service.LoadSettings() in C:\Service.svc.cs
at SyncInvokeLoadSettings(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc& rpc)

这与第二个表中的列中的数据特别相关(下例中的设置)。如果我查询另一个表(如下面示例中的用户)或排除查询该列,则效果非常好。代码示例:

using (var db = new DBEntities()) 
{
var users = (from u in db.Users
where u.PK == userid
select u).ToList();

if (users.Any())
{
var selectedUser = users.Single();
if (selectedUser.Password.Equals(passwordHash))
{
// ******************************
// * error is on the next line! *
// ******************************
var settings = (from s in db.Settings
where s.User == selectedUser.PK
select s).ToList();
}
}
}

我尝试过重新创建表、更改表名称、列名称和数据类型,但都没有帮助。如果表为空或列包含“小”数据集,那么它可以工作,但是当我其中有一行包含“大”数据时,它就会失败!

我所说的小和大是什么意思,对于 SQL 来说它们并不是真正的小和大:

  • '小'<~8k
  • '大' > ~8k

我可以确认该问题与我无关 disposing the context早期的。

<小时/> 更新

  1. 这仅在读取时有效,插入工作正常。
  2. 当我仅使用 EF 而使用 LINQ to SQL 时,不会发生这种情况。
  3. Bug logged with Microsoft因为我怀疑这不是正常行为。

最佳答案

增加上下文的 CommandTimeout。

关于.net - Azure 上的 Entity Framework "Invalid attempt to read when no data is present"和 'large' 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5310764/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com