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

Built In Scalar Function Mapping #19171

Closed
tlejmi opened this issue Dec 5, 2019 · 4 comments
Closed

Built In Scalar Function Mapping #19171

tlejmi opened this issue Dec 5, 2019 · 4 comments

Comments

@tlejmi
Copy link

tlejmi commented Dec 5, 2019

For example, if EF Core 2.2 couldn’t translate a predicate in a Where() call, it executed an SQL statement without a filter, transferred all the rows from the database, and then filtered them in-memory:

var specialCustomers = 
  context.Customers
    .Where(c => c.Name.StartsWith(n) && IsSpecialCustomer(c));

That may be acceptable if the database contains a small number of rows but can result in significant performance issues or even application failure if the database contains a large number or rows.
To evaluate a predicate condition on the client as in the previous example, developers now need to explicitly switch evaluation of the query to LINQ to Objects:


var special customers =
  context.Customers
    .Where(c => c.Name.StartsWith(n)) 
    .AsEnumerable() // switches to LINQ to Objects
    .Where(c => IsSpecialCustomer(c));

EntityFramework Core, Create and Map , scalar functions in the database to complicated builtIn
methods and well-known methods used by strings and numbers ... , and allow developers to easily create and map scalar function, to methods. So a lot of client-side evaluation will be evaluated in the database.

@roji
Copy link
Member

roji commented Dec 5, 2019

@tlejmi can you clarify exactly what you're asking for?

If you're looking to define a custom function and map it to SQL, EF Core already fully supports that. We're lacking proper documentation for this (dotnet/EntityFramework.Docs#500), but see this comment with samples.

@tlejmi
Copy link
Author

tlejmi commented Dec 7, 2019

what I meant is that Entity Framework will map by default c# built-in functions.
Like mapping c# string.Reverse() to TSQL REVERSE ( string_expression ) so that the reverse function will not be evaluated in client-side . and the same for the well-known number and string functions used as filters
Similar to this : https://entityframeworkcore.com/knowledge-base/51896918/ef-core-linq-use-scalar-function

@roji
Copy link
Member

roji commented Dec 7, 2019

@tlejmi I'm still not clear on what you're asking. EF Core knows how to translate certain methods and members, and more translations can be added if they are needed. Adding translations is not an automatic/transparent thing, and must be done manually for each case.

Are you specifically asking that we add translation support for string.Reverse? If so, you open an issue specifically for that. Otherwise you can take a look at this class, which defines all the string method translations

@ajcvickers
Copy link
Contributor

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
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

4 participants