Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'A PostgreSQL type with the name document_signature_method was not found in the database' when update collumn TypeName = "jsonb" #812

Open
wisedf opened this issue Oct 28, 2024 · 3 comments
Assignees

Comments

@wisedf
Copy link

wisedf commented Oct 28, 2024

1. Description

When we try to update any column in Postgresql when TypeName = jsonb

DocumentSignatureMethod is type Enum

image
image

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

@wisedf wisedf changed the title 'A PostgreSQL type with the name document_signature_method was not found in the database' when update TypeName = "jsonb" 'A PostgreSQL type with the name document_signature_method was not found in the database' when update collumn TypeName = "jsonb" Oct 28, 2024
@JonathanMagnan JonathanMagnan self-assigned this Oct 30, 2024
@JonathanMagnan
Copy link
Member

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

@wisedf
Copy link
Author

wisedf commented Oct 31, 2024

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.

@JonathanMagnan
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants