dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.82k stars 3.2k forks source link

Query: compilation error for queries with collection include and concat #12889

Closed maumar closed 2 years ago

maumar commented 6 years ago

query:

                var query = ctx.Gears.Include(g => g.Weapons).Concat(ctx.Gears);
                var result = query.ToList();

exception:

The input sequence must have items of type 'Microsoft.EntityFrameworkCore.TestModels.GearsOfWarModel.Gear', but it has items of type 'Microsoft.EntityFrameworkCore.Query.Internal.AnonymousObject'.
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()
    at Remotion.Linq.Clauses.Expressions.SubQueryExpression..ctor(QueryModel queryModel)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.CollectionQueryModelRewritingExpressionVisitor.CreateJoinToParentQuery(QueryModel parentQueryModel, QuerySourceReferenceExpression parentQuerySourceReferenceExpression, Expression outerTargetExpression, IForeignKey foreignKey, QueryModel targetQueryModel, ICollection`1 subQueryProjection)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.CollectionQueryModelRewritingExpressionVisitor.Rewrite(QueryModel collectionQueryModel, INavigation navigation)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.CollectionQueryModelRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
    at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
    at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
    at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
    at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
    at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
    at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
    at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
    at System.Linq.Expressions.ExpressionVisitor.VisitArguments(IArgumentProvider nodes)
    at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.CollectionQueryModelRewritingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
    at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
    at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
    at Remotion.Linq.Clauses.SelectClause.TransformExpressions(Func`2 transformation)
    at Remotion.Linq.QueryModel.TransformExpressions(Func`2 transformation)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.RewriteCollectionQueries(QueryModel queryModel)
    at Microsoft.EntityFrameworkCore.Query.Internal.IncludeCompiler.RewriteCollectionQueries()
    at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
    at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.OptimizeQueryModel(QueryModel queryModel, Boolean asyncQuery)
    at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
    at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
maumar commented 6 years ago

same goes for union

smitpatel commented 5 years ago

We don't allow different include on both sides of Set operations. Either specify same includes or do include after applying set operation.