Search code examples
c#entity-frameworknpgsql

Range type with Npgsql


I'm reverse engineering a representation of an existing Postgres database with Npgsql and EF Core. Things seem to at least be mostly in place, except I've noticed that none of my range type columns are present. This isn't too surprising considering C# has no data type that would be naturally analogous.

It seems that there is some kind of support based on this thread https://github.com/npgsql/npgsql/issues/126 and the notes here http://www.npgsql.org/dev/types.html but so far I haven't been able to find any details on how to go about implementing anything.

Edit: I found the NpgsqlRange type, but I'm getting the error 'NpgsqlRange<int>' which is not supported by current database provider. I have the modebuilder set up with .HasColumnType("int4range") as well.


Solution

  • Npgsql fully supports PostgreSQL ranges at the ADO.NET level, but the Entity Framework Core provider doesn't include support for this (frankly, nobody's requested it as range usage seems a bit rare). An issue is already open for this, I'll try to get this done for 1.2.