marten: Event Store broken with NodaTime

It seems the Event Store is broken when using NodaTime:

System.InvalidCastException: Can't cast database type timestamp with time zone to DateTime
   at Npgsql.NpgsqlDefaultDataReader.GetFieldValue[T](Int32 column) in C:\projects\npgsql\src\Npgsql\NpgsqlDefaultDataReader.cs:line 104
   at Marten.Events.StreamStateByIdHandler`1.Resolve(DbDataReader reader, IIdentityMap map, QueryStatistics stats)
   at Marten.Services.CommandRunnerExtensions.<>c__DisplayClass2_0`1.<Fetch>b__0(NpgsqlCommand c)
   at Marten.Services.ManagedConnection.Execute[T](NpgsqlCommand cmd, Func`2 func)

The call was session.Events.FetchStreamState(streamId);

This is Marten 3.5.0 with Marten.NodaTime 1.0.0.

Looking at the source code, the reason seems to be several casts to DateTime, where DateTimeOffset would (maybe?) be a more appropriate option.

https://github.com/JasperFx/marten/blob/master/src/Marten/Events/StreamStateByGuidHandler.cs#L81

Unfortunately, DateTime is used at several places through the public interface of the event store (including IEventStore), so I’m not sure if this can easily be fixed…

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 22 (8 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks @roji. I’ll be probably working on that the next weak. I’ll send then my feedback/suggestions.

@roji thanks for explanation. I understand, I’ll provide a wrapper if it’ll be needed. Thanks.