efcore.pg icon indicating copy to clipboard operation
efcore.pg copied to clipboard

[8.0.0] function cardinality(jsonb) does not exist

Open PascalArdex opened this issue 2 years ago • 2 comments

We are just upgrading to Npgsql.EntityFrameworkCore.PostgreSQL 8.0.0

We have a couple of entities mapped into JSONB columns, was working well with 7.0.0 Now it throws the following exception when we use EF.Functions.JsonExistAny

Exception has occurred: CLR/Npgsql.PostgresException
Exception thrown: 'Npgsql.PostgresException' in System.Private.CoreLib.dll: '42883: function cardinality(jsonb) does not exist

POSITION: 1011'
   at Npgsql.Internal.NpgsqlConnector.<ReadMessageLong>d__233.MoveNext()
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at Npgsql.NpgsqlDataReader.<NextResult>d__52.MoveNext()
   at Npgsql.NpgsqlDataReader.<NextResult>d__52.MoveNext()
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__119.MoveNext()
   at Npgsql.NpgsqlCommand.<ExecuteReader>d__119.MoveNext()
   at Npgsql.NpgsqlCommand.<ExecuteDbDataReaderAsync>d__112.MoveNext()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__18.MoveNext()
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.<ExecuteReaderAsync>d__18.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.<InitializeReaderAsync>d__21.MoveNext()
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.<ExecuteAsync>d__7`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.AsyncEnumerator.<MoveNextAsync>d__20.MoveNext()
   at System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable`1.ConfiguredValueTaskAwaiter.GetResult()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__67`1.MoveNext()
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.<ToListAsync>d__67`1.MoveNext()
   at Epona.Infrastructure.Repositories.ReferenceDataRepository.<GetReferenceDataByCategoryAsync>d__1.MoveNext() in C:\Users\pjacquemart\Documents\Dev\epona\backend-api\src\Infrastructure\Repositories\ReferenceDataRepository.cs:line 30

PascalArdex avatar Nov 21 '23 04:11 PascalArdex

Our entity has a generic list field public List<string> CountryCode { get; set; } = new();

We configure the dbContext with builder.Property(b => b.CountryCode).HasColumnType("jsonb");

And the snapshot generates

                 b.Property<List<string>>("CountryCode")
                        .IsRequired()
                        .HasColumnType("jsonb")
                        .HasColumnName("country_code");

PascalArdex avatar Nov 21 '23 04:11 PascalArdex

My bad the exception appears to be triggered by var query = context.ReferenceData.Where(refer => refer.CountryCode.Count == 0);

PascalArdex avatar Nov 21 '23 11:11 PascalArdex