-
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
Translate ToString() on a string column #20839
Comments
Yes, it is not supported (yet). Though I am trying to understand what query is doing exactly. Why are you calling need to call |
@smitpatel thanks for the update. Could the issue be because there is no mapping available in the _typeMapping dictionary for string type in "SqlServerObjectToStringTranslator" class. And would adding a mapping in this class resolve the issue? If yes, what shall it map to? Shall it map to VARCHAR or NVARCHAR. |
It shouldn't be added to dictionary. Rather if ToString is called on a string column then the string column should be returned. |
I am simply calling .ToString() on an Int and it errors with Framework version 6.44. I rolled back to version 6.20 and no issues. I have been do this for several years with previous versions so this is some new problem introduced after 6.20. There is a valid reason to use .ToString() so text searches of multiple concatenated columns can be performed on that database server using SQL rather than pulling all your data down first to perform searches. |
I am running a sample test in SqlServer where it is using ToString() on a string column (COL2) in the LINQ.
The test is giving following error when trying to generate SELECT query from the LINQ.
Unhandled exception. System.InvalidOperationException: The LINQ expression 'DbSet
.Where(t => t.COL2.ToString().Contains(__url_0))' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync().
Not using ToString() for string column works fine. Using any other type (for ex:- int) for COL2 with ToString() also works fine. Using ToString() for string type only gives the issue.
I am not sure if this is expected. It seems a basic scenario to support. Please could anyone confirm?
Here is the sample test-
Steps to reproduce
Simply run the above-provided test case-
Stacktrace
Further technical details
EF Core version: Microsoft.EntityFrameworkCore 3.1.3
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Core 3.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.4.2
The text was updated successfully, but these errors were encountered: