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 NullableTimeOnlyConverter : ValueConverter { /// /// Initializes a new instance of the class. /// public NullableTimeOnlyConverter() : base( d => d == null ? null : new TimeSpan?(d.Value.ToTimeSpan()), d => d == null ? null : new TimeOnly?(TimeOnly.FromTimeSpan(d.Value)) ) { } } }