My functional tests use Microsoft.EntityFrameworkCore.InMemory version 7.0.20.
When I run the functional tests for any entity that has a dateonly field I get the error.
{"Expression of type 'System.Nullable`1[System.DateOnly]' cannot be used for parameter of type 'System.DateTime' of method 'System.DateOnly FromDateTime(System.DateTime)' (Parameter 'arg0')"}
I use the dateonly converter
public class DateOnlyConverter : ValueConverter<DateOnly, DateTime>
{
/// <summary>
/// Creates a new instance of this converter.
/// </summary>
public DateOnlyConverter() : base(
d => d.ToDateTime(TimeOnly.MinValue),
d => DateOnly.FromDateTime(d))
{ }
}
The entity configuration
public void Configure(EntityTypeBuilder<Payback> builder)
{
builder.ToTable("Paybacks").HasKey(k => k.Id);
//other Properties
builder
.OwnsOne(p => p.CurrentPaybackSchedule, s =>
{
s.WithOwner();
s.Property(s => s.ScheduleDate).HasConversion<DateOnlyConverter>().HasColumnName(nameof(Payback.CurrentPaybackSchedule.ScheduleDate));
s.HasIndex(p => p.ScheduleDate);
});
}
I am not sure why the in memory database is pulling the field as a dateonly.
I have checked the versioning of all my ef packages and they all seem to be at 7.0.20.
When I run the query outside of the functional tests the code works.