DapperLib / DapperLib/Dapper

Explicit Constructor constructs the objects but doesn't pass correct values

Open
#1,501 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

public class Area
{
   [ExplicitConstructor]
   public Area(int areaId)
   {
       AreaId = areaId;
   }
   public int AreaId {get;}
}

with sql resultset equivalent to:
{ INT AreaId = 7 }

and dapper code:

await reader.ReadAsync < Area >();

passes zero as the constructor parameter. It should pass 7

Strangely enough the eventual value is actually correct even though there is no setter on the property but because the value passed into the constructor is wrong I can't do parameter validation on it which is the reason for the constructor in the first place.

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

Reproduce the reported Area example with the ReadAsync() entry point and a result containing AreaId = 7. Trace the explicit-constructor mapping path to determine why zero is passed, then verify that the constructor receives 7 while the resulting property remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sql
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.