Open GLuca74 opened 9 months ago
Note for team: still repros on latest daily; regression from 7.
Output from 8:
dbug: 2/12/2024 10:33:44.583 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query)
Compiling query expression:
'DbSet<City>()
.Select(itm => itm.CityName
.Concat("- A string"))'
Unhandled exception. System.InvalidOperationException: The LINQ expression '[-, ,A, ,s,t,r,i,n,g]' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitExtension(Expression extensionExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalProjectionBindingExpressionVisitor.Translate(SelectExpression selectExpression, Expression expression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateSelect(ShapedQueryExpression source, LambdaExpression selector)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.Translate(Expression expression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.Translate(Expression expression)
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__DisplayClass9_0`1.<Execute>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
at EFConcat.Program.Main(String[] args) in D:\code\repros\EFConcat-master\EFConcat-master\Program.cs:line 18
Output from 7:
dbug: 2/12/2024 10:32:10.245 CoreEventId.QueryCompilationStarting[10111] (Microsoft.EntityFrameworkCore.Query)
Compiling query expression:
'DbSet<City>()
.Select(itm => itm.CityName
.Concat("- A string"))'
dbug: 2/12/2024 10:32:10.395 CoreEventId.QueryExecutionPlanned[10107] (Microsoft.EntityFrameworkCore.Query)
Generated query execution expression:
'queryContext => new SingleQueryingEnumerable<IEnumerable<char>>(
(RelationalQueryContext)queryContext,
RelationalCommandCache.QueryExpression(
Client Projections:
0 -> 0
SELECT c.CityName
FROM City AS c),
null,
Func<QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator, IEnumerable<char>>,
EFConcat.TestContext,
False,
False,
True
)'
dbug: 2/12/2024 10:32:10.415 RelationalEventId.CommandExecuting[20100] (Microsoft.EntityFrameworkCore.Database.Command)
Executing DbCommand [Parameters=[], CommandType='Text', CommandTimeout='30']
SELECT [c].[CityName]
FROM [City] AS [c]
This is likely our primitive collection support treating the string as a collection, and then not being able to deal with the literal string as such.
Even though this worked, this seems like quite a questionable way to express a string concatenation (at the very least, it's extremely inefficient in .NET itself). At least as a workaround, change this to simply .Select(itm => itm.CityName + "- A string")
- the concatenation operator is a better way of doing this.
Beyond that, we can look at not treating strings as primitive collections in the query pipeline.
I am migrating a Test Project From EF Core 7.0.4 to 8.0.1 I have some tests that using 7.0.4 work, with 8.0.1 fail
the simplest query that reproduce is this :
the provider is SqlServer
the project at https://github.com/GLuca74/EFConcat reproduce the problem
the message is :
Can you please check? Thank you