I have a problem with dapper, I don't know how to fix it:
I have Poco like this:
public class Test { public long Id { get; set; } public TimeSpan? Time { get; set; } }
The Time field is the MySQL TIME field. If I download a line with Dapper with a time field with 1000 ticks, for example, and I keep this Poco unchanged, reload the same line again, the "Time" field is now at 1001 Ticks.
What am I doing wrong?
EDIT:
How do I load my line:
var testobj = Db.Query<Test>("select * from Test where Id = @id", new {id = Id});
How do I save it:
Db.Execute("replace into Test values (@Id,@Time)", testObj);
EDIT 2:
Time to save object:
{15:22:24} Days: 0 Hours: 15 Milliseconds: 0 Minutes: 22 Seconds: 24 Ticks: 553440000000 TotalDays: 0.64055555555555554 TotalHours: 15.373333333333333 TotalMilliseconds: 55344000.0 TotalMinutes: 922.4 TotalSeconds: 55344.0
and after saving:
{15:22:25} Days: 0 Hours: 15 Milliseconds: 0 Minutes: 22 Seconds: 25 Ticks: 553450000000 TotalDays: 0.64056712962962958 TotalHours: 15.37361111111111 TotalMilliseconds: 55345000.0 TotalMinutes: 922.41666666666674 TotalSeconds: 55345.0
You can see that Ticks 553440000000 and become 553450000000
EDIT 3:
I use Hans hint with my Test class as follows:
public class Test { public long Id { get; set; } private TimeSpan? _time; public TimeSpan? Time { get { if (_time.HasValue) return TimeSpan.FromTicks((long)Math.Floor(_time.Value.Ticks / 100000000d) * 100000000); return _time; } set { _time = value; } } }
and it works but it's still odd
source share