Mapping of the sbyte C# type is invalid for Npgsql / Postgres
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
If you use a sbyte type in a model, it is mapped to DbType.SByte.
Please check https://github.com/DapperLib/Dapper/blob/b272cc664d933b4b65703d26a79272d549576dff/Dapper/SqlMapper.cs#L173
However, Npgsql for Postgres doesn't seem to support DbType.SByte (An error is thrown that indicates the issue), but DbType.Int16 only. I'm not sure if there has been a recent change in the behaviour in Dapper or if it's a bug of Npgsql though.
The quick hack is to set the dynamic parameters in your query to cast to short like this (Just dummy code, Position is the sbyte property):
await using var connection = await this.GetDatabaseConnection().ConfigureAwait(false);
var sqlParams = new DynamicParameters(new
{
position = (short)node.Position,
name = node.Name
});
await connection.ExecuteAsync("UPDATE nodes SET ...", sqlParams).ConfigureAwait(false);
Can you give me information if this is a bug in Dapper or in Npgsql, please?
Version information:
- Dapper: Latest, 2.0.123.
- Npgsql: Latest, 6.0.2.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with SqlMapper.cs at the linked line around 173 and reproduce the sbyte parameter case using Dapper 2.0.123 and Npgsql 6.0.2. Compare the DbType.SByte and DbType.Int16 behavior, then establish whether the incompatibility belongs to Dapper or Npgsql and document the result or required change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, postgresql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100