Skip to content

Commit

Permalink
Refactor BytesToDateTimeConverter, so it works out-of-the-box with co…
Browse files Browse the repository at this point in the history
…mpiled models. (#1847)
  • Loading branch information
lauxjpn authored Feb 27, 2024
1 parent 90072f0 commit 284e9a5
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/EFCore.MySql/Storage/Internal/BytesToDateTimeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ private static readonly NumberToBytesConverter<long> _longToBytes

public BytesToDateTimeConverter()
: base(
v => DateTime.FromBinary((long)_longToBytes.ConvertFromProvider(v)),
v => (byte[])_longToBytes.ConvertToProvider(v.ToBinary()))
v => FromBytes(v),
v => ToBytes(v))
{
}

public static byte[] ToBytes(DateTime v)
=> (byte[])_longToBytes.ConvertToProvider(v.ToBinary());

public static DateTime FromBytes(byte[] v)
=> DateTime.FromBinary((long)_longToBytes.ConvertFromProvider(v));
}
}

0 comments on commit 284e9a5

Please sign in to comment.