Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document which DbFunction or BCL method translates to each SQL Server or other provider-specific function #2993

Open
YehudahA opened this issue Oct 25, 2015 · 6 comments
Milestone

Comments

@YehudahA
Copy link

I want to filter by DateTime property, omitting the time part:

DateTime d = DateTime.Now;
var query = myContext.Sales.Where(x => x.SaleDate.Date == d);

This code can run, but it takes all the rows and filters them in application side, instead of send the query to server.

in EF6 we have DbDunctions.TruncateTime. What about EF7?

@Daniel-Svensson
Copy link

Please choose a solution that will work for in memory queries as well (such as supporting DateTime.Date or DateTimeOffset.Date directly). So that we no longer have to write logic that must be different based on if you are executing it against a database or mock/in memory collection.

@rowanmiller
Copy link
Contributor

Already tracked by dotnet/efcore#2850

@marchy
Copy link

marchy commented Jan 2, 2021

@rowanmiller This issue did NOT get resolved by dotnet/efcore#2850, as the TruncateTime method that this issue requested – as did various comments within dotnet/efcore#2850, did not make its way way into DbFunctions.

Noted requests for this: dotnet/efcore#2850 (comment), dotnet/efcore#2850 (comment), dotnet/efcore#2850 (comment), dotnet/efcore#2850 (comment)

Can you please re-open this issue, as the requested functionality did NOT get implemented in dotnet/efcore#2850, despite this being marked as a duplicate which it's not.

@smitpatel smitpatel reopened this Jan 2, 2021
@ajcvickers
Copy link
Member

Note from triage: we should document which BCL methods have the behavior of certain database functions when translated.

@marchy This isn't implemented because EF Core translates DateTime.Date in an equivalent way--see dotnet/efcore#6778. Is there a reason you can't use this, or is it just that you were looking for TruncateTime?

@marchy
Copy link

marchy commented Jan 5, 2021

Thank you @ajcvickers, that is indeed the solution we ended up going with after some trial & error and watching what the queries translate.

As you noted the docs would be very helpful to show the migration approach for this, since these two issues are the only ones we could find that made any mention of it.

Kind thanks!

@ajcvickers ajcvickers changed the title Alternative to DbFunctions, espectially TruncateTime Document which DbFunction or BCL method translates to each SQL Server or other provider-specific function Jan 8, 2021
@ajcvickers ajcvickers added this to the Backlog milestone Jan 8, 2021
@ajcvickers ajcvickers transferred this issue from dotnet/efcore Jan 8, 2021
@roji
Copy link
Member

roji commented Jan 8, 2021

Note that we've recently added https://docs.microsoft.com/en-us/ef/core/providers/sql-server/functions, which documents all translations done by the SQL Server provider.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants