Closed lable closed 4 years ago
不要用PG的高级类型
了解! 事实上,jsonb类型如果用string是没有问题的,后续将持续观察下运行情况:
var where = $"{{\"Details\":[{{\"id\":\"{model.id}\"}}]}}";
var qry = DbFactory.GetShardingRepository()
.GetIShardingQueryable<PosOrder>()
.Where(a => EF.Functions.JsonContained(where, a.Content));
var posOrder = qry.FirstOrDefault();
报异常 Microsoft.EntityFrameworkCore.DbUpdateException : An error occurred while updating the entries. See the inner exception for details. ---- System.InvalidOperationException : Operation is not valid due to the current state of the object. 堆栈跟踪: ShardingRepository.PackAccessData(Func
1 access) 行 74 ShardingRepository.WriteTable[T](List
1 entities, Func3 accessData) 行 119 ShardingRepository.Insert[T](List
1 entities) 行 179 ShardingRepository.Insert[T](T entity) 行 171 JsonbTest.Test() 行 72 ----- Inner Stack Trace ----- JsonElement.WriteTo(Utf8JsonWriter writer) JsonConverterJsonElement.Write(Utf8JsonWriter writer, JsonElement value, JsonSerializerOptions options) JsonPropertyInfoNotNullable`4.OnWrite(WriteStackFrame& current, Utf8JsonWriter writer) JsonPropertyInfo.Write(WriteStack& state, Utf8JsonWriter writer) JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state) JsonSerializer.WriteCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options) JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options) JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options) JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options) JsonHandler.ValidateAndGetLength[TAny](TAny value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter) JsonHandler.ValidateObjectAndGetLength(Object value, NpgsqlLengthCache& lengthCache, NpgsqlParameter parameter) NpgsqlParameter.ValidateAndGetLength() NpgsqlCommand.ValidateParameters(ConnectorTypeMapper typeMapper) NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken) NpgsqlCommand.ExecuteReader(CommandBehavior behavior) NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior) DbCommand.ExecuteReader() RelationalCommand.ExecuteReader(RelationalCommandParameterObject parameterObject) ReaderModificationCommandBatch.Execute(IRelationalConnection connection)模型定义:
测试代码: