I use Npgsql.EntityFrameworkCore.PostgreSQL library. How to insert/update ltree column in PostgreSQL table via Entity Framework Core? Database table:
CREATE TABLE Entity (path ltree);
OnModelCreating:
modelBuilder.HasPostgresExtension("ltree");
...
entity.Property(e => e.Path).HasColumnName("path").HasColumnType("ltree");
Entity:
public string Path { get; set; }
And on insert i've got the error:
Npgsql.PostgresException: 42804: column "path" is of type ltree but expression is of type text
Npgsql doesn't currently support the ltree type, since PostgreSQL doesn't provide a binary input/output functions for it (and Npgsql is binary-only by default). The relevant issue is https://github.com/npgsql/npgsql/issues/699.
It still is possible to read and write ltree, like other binary-unsupported types, in text mode when using the ADO.NET API - see the Npgsql FAQ for how to do this. However, you seem to be attempting to use EF Core, where this isn't possible.