Search code examples
postgresqlentity-framework-corenpgsqlscaffolding

JSONB Column not mapping to JsonDocuent property type when scaffolding db


I cannot find any information for scaffolding a table which has a a JSONB column which should map to JsonDocument type property but instead maps to a string.

It is not an easily maintainable solution to have to manually replace every JSONB => string to JsonDocument.

Is there something I can do with the column type or maybe with the scaffold command to make JSONB columns automatically map to JsonDocument.

Database is POSTGRES and I'm using EntityframeworkCore.


Solution

  • PostgreSQL JSONB columns are scaffolded as .NET string properties - there's no easy way to change that at the moment. There are plans for more extensibility/customizability at the EF Core scaffolding level (https://github.com/dotnet/efcore/issues/4038), but at the moment you're going to have to change the CLR type yourself.