using System;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace AMWD.Common.EntityFrameworkCore.Converters
{
///
/// Defines the conversion from a nullable object to a nullable which can be handled by the database engine.
///
///
/// As of 2022-06-04 only required for Microsoft SQL server on .NET 6.0.
///
public class NullableDateOnlyConverter : ValueConverter
{
///
/// Initializes a new instance of the class.
///
public NullableDateOnlyConverter()
: base(
d => d == null ? null : new DateTime?(d.Value.ToDateTime(TimeOnly.MinValue)),
d => d == null ? null : new DateOnly?(DateOnly.FromDateTime(d.Value))
)
{ }
}
}