1
0
Files
common/AMWD.Common.EntityFrameworkCore/Converters/DateOnlyConverter.cs

25 lines
748 B
C#

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