dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.77k stars 3.19k forks source link

Warn when mapping a TimeSpan to a SQL Server time #22646

Open ajcvickers opened 4 years ago

ajcvickers commented 4 years ago

By default, EF Core maps .NET TimeSpan to SQL Server time. This is a problematic mapping because time is much more constrained than TimeSpan. We have discussed this many times; for example, see https://github.com/dotnet/efcore/issues/242#issuecomment-306174481.

With value conversions, it might be better to map TimeSpan by default to something else, as suggested in #22633. However, this is both a breaking change and may still be problematic until #10434 is robustly implemented.

However, we could generate a warning when this mapping is used.

FrankSzendzielarz commented 4 years ago

I would also just add to emphasize, though it's probably unhelpful, that mapping TimeSpan to Time is the direct conceptual analogy of mapping Length to Position. In fact, Position modulo 24. I.e. the mapping is just flat out wrong, so a breaking change might be warranted.