DapperLib / DapperLib/Dapper.Contrib

TimeSpan SqlLite

Open
#39 17 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
293
Forks
109
PR merge metrics
No merged PRs in 30d

Description

I use Dapper.Contrib with SqlLite and it does not work.

create table mytable (
    id integer primary key,
    duration text not null,
);
insert into mytable(duration) values ('0.01:00:00');

C# code

[Table("mytable")]
public class ClientTest
{
        public long Id { get; set; }
        public TimeSpan Duration { get; set; }
}

Got error:

System.Data.DataException: Error parsing column 4 (duration=0.01:00:00 - String)

When I write a TypeHandler:

public class TimeSpanHandler : SqlMapper.TypeHandler<TimeSpan>
{
    public override TimeSpan Parse(object value)
    {
        return TimeSpan.Parse((string)value);
    }

    public override void SetValue(IDbDataParameter parameter, TimeSpan value)
    {
        throw new InvalidOperationException("Never called!");
        //parameter.Value = value.ToString();
    }
}

Then it works fine for query and update, too. That's a mistake since SetValue is never called.

So we have a 2 bugs:

  1. TimeSpan for SqlLite does not work by default.
  2. TypeHandler is called just Parse, the SetValue is never called.

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 SQLite query and update using the shown ClientTest model and TimeSpanHandler. Inspect how Dapper.Contrib handles TimeSpan values and how TypeHandler invokes Parse and SetValue; done means default TimeSpan reads work and the handler's write path is exercised for updates.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, sqlite
Domain
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.