Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
DateOnly Converter & Comparer for Entity Framework Core 6.0
public class DateOnlyConverter : ValueConverter<DateOnly, DateTime>
{
public DateOnlyConverter() : base(
dateOnly => dateOnly.ToDateTime(TimeOnly.MinValue),
dateTime => DateOnly.FromDateTime(dateTime))
{
}
}
public class DateOnlyComparer : ValueComparer<DateOnly>
{
public DateOnlyComparer() : base(
(d1, d2) => d1.DayNumber == d2.DayNumber,
d => d.GetHashCode())
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment