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

Sqlite Support translation of ToString #17223

Closed
Tracked by #22950
etcircle opened this issue Aug 17, 2019 · 8 comments · Fixed by #19473
Closed
Tracked by #22950

Sqlite Support translation of ToString #17223

etcircle opened this issue Aug 17, 2019 · 8 comments · Fixed by #19473
Assignees
Labels
area-query area-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. punted-for-5.0 type-enhancement
Milestone

Comments

@etcircle
Copy link

Describe what is not working as expected.
First, I am new to asp core and this may not be expected to work like that.

I am trying to convert an Id (int) to a string so I can use Contains method to search using a pattern. However, the code breaks when I have ToString used on int.

Query.Where(s => s.Id.ToString().Contains("something"));

Example of my code
materialQuery = materialQuery.Where(s => s.Name.ToLower().Contains(searchString.ToLower()) || s.Id.ToString().Contains(searchString));

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception has occurred: CLR/System.InvalidOperationException
An exception of type 'System.InvalidOperationException' occurred in System.Private.CoreLib.dll but was not handled in user code: 'Operation is not valid due to the current state of the object.'
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable1 source, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.CountAsync[TSource](IQueryable1 source, CancellationToken cancellationToken)
at BAServer.Models.Helpers.PagedList1.<CreateAsync>d__17.MoveNext() in /Users/codingaccountant/CodingAccountant/BAServer/Models/Helpers/PagedList.cs:line 29 at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()
at BAServer.Pages.IM.Master_Data.IndexMaterial.d__11.MoveNext() in /Users/codingaccountant/CodingAccountant/BAServer/Pages/IM/Master Data/IndexMaterial.razor:line 111
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at BAServer.Pages.IM.Master_Data.IndexMaterial.d__9.MoveNext() in /Users/codingaccountant/CodingAccountant/BAServer/Pages/IM/Master Data/IndexMaterial.razor:line 87


### Further technical details
EF Core version: 3.0 Preview 8
Database Provider: SQLite
Operating system: macOS
IDE: VS Code
@etcircle
Copy link
Author

etcircle commented Aug 17, 2019

@ajcvickers ajcvickers changed the title Id Int(32) -> To String in query (Preview 8) Support translation of String.Contains in Where predicate Aug 19, 2019
@ajcvickers ajcvickers added this to the Backlog milestone Aug 19, 2019
@smitpatel
Copy link
Contributor

Sqlite provider does not have support for ToString methods

@etcircle
Copy link
Author

Ah, thanks for the answer!

@smitpatel smitpatel changed the title Support translation of String.Contains in Where predicate Sqlite Support translation of ToString Aug 20, 2019
@ajcvickers ajcvickers modified the milestones: Backlog, 5.0.0 Nov 20, 2019
@smitpatel smitpatel added the good first issue This issue should be relatively straightforward to fix. label Jan 2, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 3, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 3, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 3, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 3, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 4, 2020
ralmsdeveloper added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Jan 12, 2020
@smitpatel smitpatel assigned bricelam and unassigned smitpatel Feb 14, 2020
@smitpatel
Copy link
Contributor

Assigning to @bricelam since PR is assigned to him.

@jons-aura
Copy link

We use SQLite for our unit tests (and SQL Server for production) and it works great for the most part but I just hit an issue with converting numbers to strings and the workaround I found for that is to explicitly call ToString(), which then breaks all the relevant tests. The conversion issue is #20732

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label May 29, 2020
@smitpatel smitpatel assigned maumar and unassigned smitpatel Jun 10, 2020
@smitpatel
Copy link
Contributor

Passing to @maumar

@ajcvickers ajcvickers modified the milestones: 5.0.0, Backlog Jun 10, 2020
@ajcvickers ajcvickers added punted-for-5.0 consider-for-current-release and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels Jun 10, 2020
smitpatel added a commit to ralmsdeveloper/EntityFrameworkCore that referenced this issue Oct 30, 2020
@smitpatel smitpatel assigned smitpatel and unassigned bricelam and maumar Oct 31, 2020
@smitpatel smitpatel modified the milestones: Backlog, 6.0.0 Oct 31, 2020
@smitpatel smitpatel added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed consider-for-current-release labels Oct 31, 2020
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-preview1 Jan 27, 2021
@jons-aura
Copy link

If there's a point release before 6.0.0 will this make it into that or will this definitely not land before 6.0.0? I did some ugly work arounds for this once and just hit another place it looks like I'll have to do that again and would really rather not.

@roji
Copy link
Member

roji commented Feb 1, 2021

@jons-aura as this is a feature, we won't be backporting this to 5.0.x; we only patch for bugs. However, this will be out in a couple weeks as 6.0.0-preview1, and our previews are quite stable (undergo the same test verification suite etc.), and we react quickly to regressions found on them - so I'd consider using that.

@ajcvickers ajcvickers modified the milestones: 6.0.0-preview1, 6.0.0 Nov 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-query area-sqlite closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. community-contribution customer-reported good first issue This issue should be relatively straightforward to fix. punted-for-5.0 type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants