DapperLib / DapperLib/Dapper

Dapper mapping bool/bit to true

Open
#1,867 0 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

I am using dapper to map the result of query to a strongly typed class(Query<T>). However, dapper always map bit(in mssql)/boolean(postgre) to true. After testing, if I map false the bit/bool value to string, i get 'False', but when i map to bool, it becomes true.
In class T, I have a member like public bool mybool { get; set; } then the query is somthing like this:

        public T SelectByID<T>(string tableName, int id, string fields = "*")
        {
            string sql = $"SELECT {fields} FROM {tableName} WHERE ID = {id}";
            return _connection.QueryFirstOrDefault<T>(sql, null, _transaction);
        }

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 by reproducing the issue with QueryFirstOrDefault, a class containing the bool property, and a false bit/boolean result from SQL Server or PostgreSQL. Trace the mapping path for boolean values and compare it with the string result shown in the report. Done means a false database value maps to false in the strongly typed class, with regression coverage for the reported case.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, postgresql, sql
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.