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.8k stars 3.2k forks source link

SQL Server: translate `dateOnly.ToDateTime(timeOnly)` to `DATETIMEFROMPARTS` #35076

Open IanKemp opened 1 week ago

IanKemp commented 1 week ago

As title.

Transform to

EF.Functions.DateTimeFromParts(
    dateOnly.Year, dateOnly.Month, dateOnly.Day,
    timeOnly.Hour, timeOnly.Minute, timeOnly.Second, timeOnly.Millisecond)

which would then translate (using the current mapping of EF.Functions.DateTimeFromParts) to the SQL

DATETIMEFROMPARTS(
    DATEPART(year, dateOnly), DATEPART(month, dateOnly), DATEPART(day, dateOnly),
    DATEPART(hour, timeOnly), DATEPART(minute, timeOnly), DATEPART(second, timeOnly), DATEPART(millisecond, timeOnly))
roji commented 1 week ago

Putting in the backlog as a possible translation. One problem with this kind of translation is that it duplicates its argument (in this many times over); this is OK if the argument is a simple value (column), but if it's e.g. a complex scalar subquery, that would reevaluate the subquery many times over. At least at first, I'd not perform the translation in that case.

mseada94 commented 1 day ago

@roji I would like to work on this method translation. I am new to the repo, I will try to understand the translation and then start working on the code. I think this PR would be a good reference to understand the method translation #31180

roji commented 19 hours ago

@mseada94 sure thing, go ahead.