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

Query: compilation error for query projecting collection followed by FirstOrDefault accessing another collection #22896

Closed
maumar opened this issue Oct 6, 2020 · 0 comments · Fixed by #25795
Assignees
Labels
area-query closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@maumar
Copy link
Contributor

maumar commented Oct 6, 2020

query:

ss.Set<Level1>()
                    .Where(l1 => l1.Id < 2)
                    .Select(l1 => new
                    {
                        l1.Id,
                        Pushdown = l1.OneToMany_Optional1
                            .Where(x => x.Name == "L2 02")
                            .FirstOrDefault().OneToMany_Optional2.ToList()
                    })

exception:

GenericArguments[2], 'System.Collections.Generic.ICollection`1[Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel.Level3]', on 'Void PopulateCollection[TCollection,TElement,TRelatedEntity](Int32, Microsoft.EntityFrameworkCore.Query.QueryContext, System.Data.Common.DbDataReader, Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryResultCoordinator, System.Func`3[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,System.Object[]], System.Func`3[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,System.Object[]], System.Func`3[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,System.Object[]], System.Collections.Generic.IReadOnlyList`1[Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer], System.Collections.Generic.IReadOnlyList`1[Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer], System.Collections.Generic.IReadOnlyList`1[Microsoft.EntityFrameworkCore.ChangeTracking.ValueComparer], System.Func`5[Microsoft.EntityFrameworkCore.Query.QueryContext,System.Data.Common.DbDataReader,Microsoft.EntityFrameworkCore.Query.Internal.ResultContext,Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryResultCoordinator,TRelatedEntity])' violates the constraint of type 'TRelatedEntity'.
    ---- System.Security.VerificationException : Method Microsoft.EntityFrameworkCore.Query.RelationalShapedQueryCompilingExpressionVisitor+ShaperProcessingExpressionVisitor.PopulateCollection: type argument 'System.Collections.Generic.ICollection`1[Microsoft.EntityFrameworkCore.TestModels.ComplexNavigationsModel.Level3]' violates the constraint of type parameter 'TRelatedEntity'.
  Stack Trace: 
    RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)
    RuntimeMethodInfo.MakeGenericMethod(Type[] methodInstantiation)
    ShaperProcessingExpressionVisitor.VisitExtension(Expression extensionExpression) line 755
    ShaperProcessingExpressionVisitor.ProcessShaper(Expression shaperExpression, RelationalCommandCache& relationalCommandCache, LambdaExpression& relatedDataLoaders) line 277
    RelationalShapedQueryCompilingExpressionVisitor.VisitShapedQuery(ShapedQueryExpression shapedQueryExpression) line 64
    ShapedQueryCompilingExpressionVisitor.VisitExtension(Expression extensionExpression) line 95
    QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) line 179
    Database.CompileQuery[TResult](Expression query, Boolean async) line 72
    QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) line 112
    <>c__DisplayClass9_0`1.<Execute>b__0() line 96
    CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) line 76
    QueryCompiler.Execute[TResult](Expression query) line 92
    EntityQueryProvider.Execute[TResult](Expression expression) line 79
    EntityQueryable`1.GetEnumerator() line 91
    List`1.ctor(IEnumerable`1 collection)
@smitpatel smitpatel self-assigned this Oct 6, 2020
@AndriySvyryd AndriySvyryd added this to the Backlog milestone Oct 9, 2020
@ajcvickers ajcvickers modified the milestones: Backlog, 6.0.0 Nov 5, 2020
smitpatel added a commit that referenced this issue Aug 30, 2021
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Aug 30, 2021
smitpatel added a commit that referenced this issue Aug 31, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0, 6.0.0-rc2 Sep 1, 2021
@ajcvickers ajcvickers modified the milestones: 6.0.0-rc2, 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 closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants