Skip to content

Instantly share code, notes, and snippets.

@marcominerva
Created January 7, 2022 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcominerva/773768729082febd50937f6f650daa27 to your computer and use it in GitHub Desktop.
Save marcominerva/773768729082febd50937f6f650daa27 to your computer and use it in GitHub Desktop.
TimeOnly Converter & Comparer for Entity FrameworkCore 6.0
public class TimeOnlyConverter : ValueConverter<TimeOnly, TimeSpan>
{
public TimeOnlyConverter() : base(
timeOnly => timeOnly.ToTimeSpan(),
timeSpan => TimeOnly.FromTimeSpan(timeSpan))
{
}
}
public class TimeOnlyComparer : ValueComparer<TimeOnly>
{
public TimeOnlyComparer() : base(
(t1, t2) => t1.Ticks == t2.Ticks,
t => t.GetHashCode())
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment