用于查询 CockroachDB 的实体框架 ArgumentOutOfRangeException?

问题描述

我有一个 kubernetes 集群,运行一些现有的 ASP.NET 应用程序,这些应用程序曾经在 Postgresql 数据库前使用实体框架。我使用 Npgsql.EntityFrameworkCore.Postgresql 客户端驱动程序。我正在尝试用 CockroachDB 替换数据库,我已经做到了:

  • 我可以创建和部署 cockroachdb
  • 我可以从应用程序连接到 cockroachdb
  • 正确创建了数据库

我有一个简单的插入,我已经确认它在 postgres 上有效,但在 cockroachdb 上不起作用。我已启用敏感数据记录功能,但我可以获得更多信息吗?

我发现了这个未解决的问题:https://github.com/cockroachdb/cockroach/issues/48050

我已尝试使用 options.UseNpgsql(connectionString,o => o.SetPostgresversion(9,6))optionsBuilder.UseSerialColumns(); 解决此问题,以避免与 Postgres 10.x 的兼容性问题 - 两者似乎都无法解决我的问题。

SQL查询错误

Executed DbCommand (5ms) [Parameters=[@p0='1d808b9a-6cb3-48b6-b5a3-961f98e941b9' (Nullable = false),@p1='2021-02-06T22:28:01.3495134+00:00' (DbType = DateTime),@p2='my@email.com' (Nullable = false),@p3='2021-02-06T22:28:01.3495134+00:00' (DbType = DateTime)],CommandType='Text',CommandTimeout='30']
      INSERT INTO "Accounts" ("MyIdentityName","Created","Email","LastChanged")
      VALUES (@p0,@p1,@p2,@p3)
      RETURNING "Id";
      An exception occurred in the database while saving changes for context type 'KlusterManager.Data.DataMainDbContext'.
      Microsoft.EntityFrameworkCore.dbupdateException: An error occurred while updating the entries. See the inner exception for details.
       ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
         at System.Collections.Generic.List`1.get_Item(Int32 index)
         at Npgsql.EntityFrameworkCore.Postgresql.Update.Internal.NpgsqlModificationCommandBatch.ConsumeAsync(RelationalDataReader reader,CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection,CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection,CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.Update.Internal.BatchExecutor.ExecuteAsync(IEnumerable`1 commandBatches,IRelationalConnection connection,CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(IList`1 entriesToSave,CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.ChangeTracking.Internal.StateManager.SaveChangesAsync(DbContext _,Boolean acceptAllChangesOnSuccess,CancellationToken cancellationToken)
         at Npgsql.EntityFrameworkCore.Postgresql.Storage.Internal.NpgsqlExecutionStrategy.ExecuteAsync[TState,TResult](TState state,Func`4 operation,Func`4 verifySucceeded,CancellationToken cancellationToken)
         at Microsoft.EntityFrameworkCore.DbContext.SaveChangesAsync(Boolean acceptAllChangesOnSuccess,CancellationToken cancellationToken)
      Microsoft.EntityFrameworkCore.dbupdateException: An error occurred while updating the entries. See the inner exception for details.
       ---> System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
         at System.Collections.Generic.List`1.get_Item(Int32 index)
         at Npgsql.EntityFrameworkCore.Postgresql.Update.Internal.NpgsqlModificationCommandBatch.ConsumeAsync(RelationalDataReader reader,CancellationToken cancellationToken)

我也将 Account 模型用作 gRPC DTO,这意味着它具有 protobuf 注释。这些中的任何一个会干扰实体框架吗?同样,该查询适用于 Postgres,但不适用于 CockroachDB

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...