'A PostgreSQL type with the name document_signature_method was not found in the database' when update collumn TypeName = "jsonb"
1. Description
When we try to update any column in Postgresql when TypeName = jsonb
DocumentSignatureMethod is type Enum
2. Exception
'A PostgreSQL type with the name document_signature_method was not found in the database'
3. Table DDL
CREATE TABLE public.documents ( id uuid NOT NULL, signed_at timestamp NULL, status int2 NOT NULL, pending_signature_methods jsonb DEFAULT '[]'::jsonb NOT NULL, CONSTRAINT documents_pk PRIMARY KEY (id) );
Postgresql 15; Assembly Z.EntityFramework.Plus.EFCore, Version=6.103.6.0
Hello @wisedf ,
Unfortunately, there is no plan to support this for the moment. This is not we would not like, but time is missing ;(
Best Regards,
Jon
A provisional solution adopted is to create a specific converter for the property within the context inside OnModelCreating(ModelBuilder modelBuilder).
[Column("erp_collection_agreement_ids", TypeName = "jsonb")]
public List<string> ErpCollectionAgreementIds { get; set; }
Ex.:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<CollectionAgreement>().Property(t => t.ErpCollectionAgreementIds).HasJsonConversionList<String>();
}
public static PropertyBuilder<List<T>> HasJsonConversionList<T>(this PropertyBuilder<List<T>> builder)
{
return builder.HasConversion(
v => v != null ? JsonSerializer.Serialize(v, (JsonSerializerOptions)null) : null,
v => v != null ? JsonSerializer.Deserialize<List<T>>(v, (JsonSerializerOptions)null) : new List<T>(),
new ValueComparer<List<T>>(
(c1, c2) => c1.SequenceEqual(c2),
c => c.Aggregate(0, (a, v) => HashCode.Combine(a, v != null ? v.GetHashCode() : 0)),
c => c != null ? c.ToList() : new List<T>()
)
);
}
This solution was adopted, and after that, it worked normally.
Awesome,
Thank you for letting us know about this solution. It looks like a very good fix that you can apply on your side.
Best Regards,
Jon