Sylvan icon indicating copy to clipboard operation
Sylvan copied to clipboard

Map `DbType.Date` to `DateOnly` on targets where it's available

Open 0xced opened this issue 8 months ago • 3 comments

It would probably a good idea to merge https://github.com/MarkPflug/Sylvan.Data.Excel/pull/198 first, though.

0xced avatar May 01 '25 13:05 0xced

@0xced, I'm reluctant to merge this. I'd like to maintain consistent behavior between frameworks, and this would potentially cause a break if someone moved from an older framework to a new one that supports these new types. I agree with what you're trying to achieve though, as DateOnly feels like the more appropriate type for this scenario. I'm wondering if there is a way to accomplish this via the data binder instead, allowing DateTime values to be bound to DateOnly properties, maybe requiring that the time component is zero.

MarkPflug avatar May 02 '25 17:05 MarkPflug

I just pushed ab727698d1d2d844a3c2d0bc07ae6745122dc522 which introduces a new AppContext switch to restore the previous behaviour of mapping DbType.Date to DateTime (instead of DateOnly).

AppContext.SetSwitch("Sylvan.Data.MapDateToDateTime", true);

This allows to move forward with the new DateOnly type while also providing an escape hatch if needed.

0xced avatar May 02 '25 21:05 0xced

EF Core 8 went with a breaking change regarding this topic too.

SQL Server date and time now scaffold to .NET DateOnly and TimeOnly

0xced avatar May 22 '25 17:05 0xced