DapperLib / DapperLib/DapperAOT

How to deal with DBNull but want to go into a normal field

Open
#164 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
C#
Stars
472
Forks
43
Avg merge
1d 4h
Merged PRs (30d)
18

Description

So the conversion works ok with Dapper reflection, but with AOT it throws at this point
result.PrimaryIncome = GetValue<double>(reader, columnOffset);

I think the value might be null, but the field type is not "Nullable" (Legacy code, and is also serialised elsewhere, so defo cannot change!)

Is there some attribute that can be applied to state that DBNulls are converted to zero's (Or even Nan for doubles?)

Code:

            IEnumerable<MLModelInput> result = connection.Query<MLModelInput>(sProcName,
                    new { PoolCutOffDate = poolCutOffDate },
                    buffered: false,
                    commandTimeout: 1800,   // Set timeout to 30 mins
                    commandType: CommandType.StoredProcedure);
            return result.ToArray();  // <- Boom with AOT!!

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the AOT failure at result.ToArray() and review the mapping call result.PrimaryIncome = GetValue(reader, columnOffset). Check how DBNull is handled when the target field is a non-nullable double. Done requires a documented or implemented resolution for the requested DBNull-to-zero or NaN behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.