Efcore: Query: compilation error for queries with Concat on two entities and scalar projection on top

Created on 29 Jun 2017  路  6Comments  路  Source: dotnet/efcore

query:

context.Gears.Concat(context.Gears).Select(g => g.Nickname);

exception:

The input sequence must have items of type 'Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear', but it has items of type 'System.String'.
Parameter name: inputInfo
    at Remotion.Linq.Clauses.ResultOperatorBase.CheckSequenceItemType(StreamedSequenceInfo inputInfo, Type expectedItemType)
    at Remotion.Linq.Clauses.ResultOperators.ConcatResultOperator.GetOutputDataInfo(IStreamedDataInfo inputInfo)
    at Remotion.Linq.QueryModel.<GetOutputDataInfo>b__0(IStreamedDataInfo current, ResultOperatorBase resultOperator)
    at System.Linq.Enumerable.Aggregate[TSource,TAccumulate](IEnumerable`1 source, TAccumulate seed, Func`3 func)
    at Remotion.Linq.QueryModel.GetOutputDataInfo()
    C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(570,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.TrackResults(QueryModel queryModel)
    C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(287,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
    C:\git\EntityFramework\src\EFCore.Relational\Query\RelationalQueryModelVisitor.cs(1157,0): at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
    C:\git\EntityFramework\src\EFCore\Query\EntityQueryModelVisitor.cs(171,0): at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
    C:\git\EntityFramework\src\EFCore\Storage\Database.cs(70,0): at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
    C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(164,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, IDiagnosticsLogger`1 logger, Type contextType)
    C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(103,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_0`1.<Execute>b__0()
    C:\git\EntityFramework\src\EFCore\Query\Internal\CompiledQueryCache.cs(69,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
    C:\git\EntityFramework\src\EFCore\Query\Internal\CompiledQueryCache.cs(44,0): at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
    C:\git\EntityFramework\src\EFCore\Query\Internal\QueryCompiler.cs(99,0): at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
    C:\git\EntityFramework\src\EFCore\Query\Internal\EntityQueryProvider.cs(62,0): at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
    at Remotion.Linq.QueryableBase`1.GetEnumerator()
    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

Looks like we are creating invalid QM that relinq can't quite handle when we ask for it's OutputDataInfo during tracking

closed-fixed punted-for-2.0 type-bug

Most helpful comment

@generik0 This issue is in the Backlog milestone. This means that it is not going to happen for the 3.0 release. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

All 6 comments

The issue is introduced by ConvertEntityQueryableToSubQuery in QueryOptimizer

Hitting this issue in a project ported from EF 6. Any workarounds for now?

@flipchart - Try following query
context.Gears.Select(g => g.Nickname).Concat(context.Gears.Select(g => g.Nickname));

same issue here, either using Concat() or Union()

@ajcvickers Any update? I have same issue if:
Demo code:
c# var actuals = db.Reports.Include(x => x.ReportsDetails).OrderBy(x=>x.Time) .Where(x => ids.Contains(x.Id)).Take(1); var actualsBetween = db.Reports.Include(x => x.ReportsDetails) .Where(x => ids.Contains(x.Id) && fromDateTime <= x.Time && x.Time <= toDateTime); actuals = actuals.Concat(actualsBetween);

@generik0 This issue is in the Backlog milestone. This means that it is not going to happen for the 3.0 release. We will re-assess the backlog following the 3.0 release and consider this item at that time. However, keep in mind that there are many other high priority features with which it will be competing for resources.

Was this page helpful?
0 / 5 - 0 ratings