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.5k stars 3.13k forks source link

Add EF.Functions.Format for SQL Server string formattting #32686

Open Joaoalen98 opened 6 months ago

Joaoalen98 commented 6 months ago

When i use Datetime.ToString( ) to format date for group registers by MM/yyyy for example, it would be nice if EF could translate this for native SQL function FORMAT.

Simple example below: imagem_2023-12-28_204416464

roji commented 6 months ago

@Joaoalen98 the problem is that the .NET format strings accepted by DateTime.ToString() don't necessarily correspond to the ones that SQL Server FORMAT accepts; we've traditionally avoided adding translations where things don't correspond like that (though there have been some exceptions). A possibly better way is to add an EF.Functions.Format which corresponds exactly to SQL Server FORMAT.