Column "path" is of type ltree but expression is of type text

.net c# entity-framework-core npgsql postgresql

Question

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

1
0
11/21/2017 1:31:13 PM

Accepted Answer

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.

1
11/21/2017 8:14:21 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow