-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
SQL builder appends '= 1' after custom sql function regardless return type #11316
Comments
SqlFunctionExpressions must have a return type, in your example it is bool. In your case a default compare to 1 is being added to the expression tree. You would need to update the query generator to ignore the comparison when generating the sql for your function. Freetext support for Sql Server was added in pr #10480. Take a look at the changes made to SqlServerQuerySqlGenerator.cs to see what I am talking about. |
Ok, I see that there's a change in VisitBinary method. Don't you think that that |
Duplicate of #9143 The SQL Gen phase has a expression visitor which converts values to condition and vice-versa based on part of SQL statement. That visitor is private at present so provider cannot override that code. Presently that visitor assumes that all SqlFunctionExpression are of value type. Hence when it appears in where predicate it will convert to condition so append Till #9143 is fixed the only way to fix this is to provider Custom Sql Gen which does the same as FREETEXT. |
Thanks for quick reply :) Now the problem is 100% clear. I wish I could fix it by myself and contribute your great project, but I'm not smart enough for that :) |
I'm digging into EF Core internals. I try to extend EF capabilities by adding CONTAINS function support from SQL Server text analysis package.
What I have done:
Extended
SqlServerCompositeMethodCallTranslator
where I append customFreeTextTranslator
This
FreeTextTranslator
translates custom extension methodContainsText
ofstring
toCONTAINS
query.Here's the code of translator (idea I borrowed from
SqlServerContainsOptimizedTranslator
):This code almost works, however this code:
translates to that SQL with
=1
in the end which is not syntactically correctI tried to use
SqlFragmentExpression
but it didn't help either. Here you can find full code.I think SQL builder should respect SqlFunction return type and not append
= 1
by default.Further technical details
EF Core version: 2.1.0-preview1-final
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system: Windows 10 16299
IDE: Visual Studio 2017
The text was updated successfully, but these errors were encountered: