nhibernate-core icon indicating copy to clipboard operation
nhibernate-core copied to clipboard

Possible NH issue taking liberties with PG IUserType

Open mwpowellhtx opened this issue 1 month ago • 2 comments

See the issue here, I start there because the exception is being thrown, somehow or other Npgsql is seeing my IUserType as though it was DbType.UInt64. However, as I explained in the issue, we are doing no such thing training the user type as such, rather we explicitly want DbType.Decimal mapped against the database NpgsqlDbType.Numeric. Have set breakpoints in the user type during the NullSafeSet and see ZERO evidence that any ulong ever crosses its threshold. The only other thing possible interceding in our mapping behalf is NH in that instance; or technically we are using Fluent NHibernate to facilitate mapping, but that is neither here nor there, because the issues being thrown are driver level.

Been up and down several of the dotnet CSharp and NH forums and no one seems to be finding this. But it is a block, we need for this to work correctly. I don't think it will be a matter of efcore versus NH or FNH, assuming it is somehow a database, dialect, or other type of issue. Could be wrong, assuming what else is going on in the NH layers.

Would be happy to jump on a discord screen share or something similar to try and diagnose the issue further.

mwpowellhtx avatar Nov 10 '25 02:11 mwpowellhtx

We do test pg, so, best way to get this moving is to supply a test case that would demonstrate the issue.

Then we would be able to check if that is a NH issue or not.

fredericDelaporte avatar Nov 10 '25 17:11 fredericDelaporte

Do you have a test case for the mapping in question, that is ulong to NUMERIC(20,0) vis-a-vis decimal. That is, we receive a decimal from the driver, and are converting from ulong (domain side) to decimal on the return trip. However, somewhere in that process Npgsql (?) or perhaps NH is taking liberties with the DbType.

One thing I can tell you 💯 is that when it leaves our value converter, it is traveling to the database as a decimal, not ulong. So as long as we have configured IUserType correctly, which has been working overall to this point, correctly, which I think we have, there is zero reason why it should not work. Definitely should NOT be throwing this exception from the Npgsql driver level IMHO, I cannot underscore that assessment strongly enough.

I've asked around and folks generally blanket statement carte blanche declare "it works" but in this specific area, crickets 🦗 . I'm open to suggestions, but I do not have the bandwidth to get drawn into other projects at this point beyond the subscription model.

mwpowellhtx avatar Nov 10 '25 17:11 mwpowellhtx