Error parsing null value into nullable property
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 18.4k
- Forks
- 3.7k
- Avg merge
- 5h 8m
- Merged PRs (30d)
- 1
Description
I have a wrapper around IDataReader that returns null when the value is DBNull, like this:
public class MyDataReaderWrapper : IDataReader
{
public object GetValue(int index)
{
if (_wrappedDataReader.IsDBNull(index)) return null;
...
}
}
When using the following code Dapper gives "Error parsing column 0(Value=NULL)".
public class Test
{
public int? Value { get; set; }
}
...
var test = _wrappedDBConnection.Query<Test>("SELECT NULL AS Value FROM DUAL");
I understand that Dapper already deals with DBNull, but my application uses this wrapper so that we don't have to deal with DBNull when using IDataReader directly.
I think Dapper should still work when mapping a null value to a nullable property.
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
Reproduce the issue with MyDataReaderWrapper, IDataReader.GetValue, the nullable Test.Value property, and the Query call shown in the report. Trace Dapper's column-mapping path for a null object value and compare it with DBNull handling. Done means the query maps the wrapper's null to int? Value without an error, with a regression test covering the example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100