DapperLib / DapperLib/Dapper

Dapper does not find correct constructor for objects with MySqlDateTime in mySql

Open
#456 0 comments 1 reaction 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

When attempting to materialize objects with System.DateTime or MySql.Data.Types.MySqlDateTime, Dapper Query<T>() methods throw this exception:

A parameterless default constructor or one matching signature (MySql.Data.Types.MySqlDateTime Item1) is required for System.Tuple`1[[System.DateTime, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]] materialization

Examples:

var date = con.Query<DateTime>( "SELECT NOW()" ); // works
var date2 = con.Query<Tuple<DateTime>>( "SELECT NOW() as Item1" ); // throws above exception
var date3 = con.Query<MySql.Data.Types.MySqlDateTime>( "SELECT NOW()" ); //works
var date4 = con.Query<Tuple<MySql.Data.Types.MySqlDateTime>>( "SELECT NOW() as Item1" ); // throws similar exception as above
var my = con.Query<Tuple<long, string>>( "SELECT 1 as Item1, 'tab' as Item2;" ); // works, tuples are correctly populated from Dapper for non-datetimes
var date5 = con.Query<Tuple<DateTime>>( "SELECT GETDATE() as Item1;" ); //tsql, this does work

This bug also occurs with other wrapper types:

class Wrapper
{
    public Wrapper(MySql.Data.Types.MySqlDateTime x)
    {

    }
}
var wrap = con.Query<Wrapper>( "SELECT NOW() as x" ); // throws "Additional information: A parameterless default constructor or one matching signature (MySql.Data.Types.MySqlDateTime x) is required for Wrapper materialization"

This occurs with MySql 4.1 / MySql.Data 6.2.5

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 failure through the Query() examples for Tuple, Tuple, and Wrapper. Trace Dapper's constructor selection and materialization for provider-returned MySqlDateTime values; done means these wrapper and tuple queries materialize successfully while existing non-datetime tuple queries continue to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, mysql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.