npgsql: Npgsql.NpgsqlCommand.DeriveParametersForQuery fails on un-mapped Enums

Exception message:

'No mapping found for PostgreSQL type [MyEnum]'

Stack trace:

   at Npgsql.TypeMapping.ConnectorTypeMapper.GetNpgsqlTypeByOid(UInt32 oid)
   at Npgsql.NpgsqlCommand.DeriveParametersForQuery()
   at Npgsql.NpgsqlCommand.DeriveParameters()
   at Npgsql.NpgsqlCommandBuilder.DeriveParameters(NpgsqlCommand command)
   ...

Further technical details

Npgsql version: 3.3.0-command-caching PostgreSQL version: 9.6.5 Operating system: Win10

Other details: I think it fails for mapped enums too with

System.InvalidOperationException: Invalid parameter type: 55253
   at Npgsql.TypeMapping.ConnectorTypeMapper.GetNpgsqlTypeByOid(UInt32 oid)
   at Npgsql.NpgsqlCommand.DeriveParametersForQuery()
   at Npgsql.NpgsqlCommand.DeriveParameters(

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 42 (42 by maintainers)

Most upvoted comments

@Brar Great job ! I suggest create a separate PR for composite types so I won’t be blocked on enums.

Ok, I’ve implemented NpgsqlParameter.PostgresType as discussed here (see #1740 ) except lazily loading of composite types, which will take some more time.

After seeing your code example I understand a bit more - the whole point is to not require the user to write a CLR enum and to map it, but rather to access some database and be able to interact with it (enums included) without any prior preparation. Contrary to what I said before I think I’m now OK with adding a PostgresType property to NpgsqlParameter, even though it may be a slight abuse of that class. But we can consider NpgsqlParameter not just as a way to send data to the database, but also as a way of understanding exactly what kind of data would need to be sent, in which sense it makes sense to infer the PostgreSQL type as well. I can even imagine other uses for this property - if a PostgreSQL domain is defined, user code may need to be aware of that, e.g. distinguishing a postal code domain type from the actual text storage type. What do you think @Brar?

Well, I’m always willing to support the features that are actually requested and I also find Dmitrys work pretty exciting (and also because, despite my general interest, I’ve got no clue about F# and am happy to see and understand its strengths) I 'will not oppose here.

I’ll go ahead and implement it within #1740 and we’ll see if we like the result or not.