Skip to content

Map DbType.Date to DateOnly on targets where it's available - #281

Open
0xced wants to merge 2 commits into
MarkPflug:mainfrom
0xced:Date-to-DateOnly
Open

Map DbType.Date to DateOnly on targets where it's available#281
0xced wants to merge 2 commits into
MarkPflug:mainfrom
0xced:Date-to-DateOnly

Conversation

@0xced

@0xced 0xced commented May 1, 2025

Copy link
Copy Markdown
Contributor

It would probably a good idea to merge MarkPflug/Sylvan.Data.Excel#198 first, though.

@0xced
0xced force-pushed the Date-to-DateOnly branch from cb1ff94 to 09a90be Compare May 2, 2025 09:24
@MarkPflug

Copy link
Copy Markdown
Owner

@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.

@0xced

0xced commented May 2, 2025

Copy link
Copy Markdown
Contributor Author

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

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

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

@0xced

0xced commented May 22, 2025

Copy link
Copy Markdown
Contributor Author

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
0xced force-pushed the Date-to-DateOnly branch from ab72769 to e7cbd4d Compare May 27, 2025 16:01
@0xced
0xced force-pushed the Date-to-DateOnly branch 2 times, most recently from 32224b6 to 57f0630 Compare March 25, 2026 20:53
@0xced
0xced force-pushed the Date-to-DateOnly branch from 57f0630 to 91ad32b Compare April 14, 2026 12:43
0xced added 2 commits May 18, 2026 21:17
…Time

The behaviour of mapping mapping DbType.Date to DateTime (instead of DateOnly) can be restored by setting the new `Sylvan.Data.MapDbDateToClrDateTime` AppContext switch.

```csharp
AppContext.SetSwitch("Sylvan.Data.MapDbDateToClrDateTime", true);
```
@0xced
0xced force-pushed the Date-to-DateOnly branch from 91ad32b to 90b4a18 Compare May 18, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants