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: orderby + include + complex projection doesn't work #5612

Closed
maumar opened this issue Jun 1, 2016 · 1 comment
Closed

Query: orderby + include + complex projection doesn't work #5612

maumar opened this issue Jun 1, 2016 · 1 comment
Assignees
Labels
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 Jun 1, 2016

copied from one of the comments in #4637

model:

public class Job {

  public Int32 Id { get; set; }
  public String CountryCode { get; set; }
  public String City { get; set; }
  public Boolean IsEnabled { get; set; }
  public virtual Country Country { get; set; }
} 

public class Country {
  public String Code { get; set; }
  public String Name { get; set; }
  public virtual ICollection<Job> Jobs { get; set; } = new List<Job>();
}

query:

var result = await _context.Jobs
   .OrderBy(x => x.Start)
   .Include(x => x.Country)            
   .Where(x => x.IsEnabled)
     .Skip(0).Take(10)
     .Select(x =>
         new {
            Id = x.Id,
            Country = new {
              Code = x.Country.Code,
              Name = x.Country.Name
            }
          })            
        .ToListAsync();

Exception:

The given expression 'new <>f__AnonymousType12(Id = [x].Id, Country = new <>f__AnonymousType22(Code = Property([x], "CountryCode"), Name = [x.Country].Name))' does not contain the searched expression '[x]' in a nested NewExpression with member assignments or a MemberBindingExpression.
Parameter name: fullExpression
at Remotion.Linq.Clauses.ExpressionVisitors.AccessorFindingExpressionVisitor.FindAccessorLambda(Expression searchedExpression, Expression fullExpression, ParameterExpression inputParameter)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.IncludeNavigations(QueryModel queryModel, IReadOnlyCollection1 includeSpecifications) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsyncTResult
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable1.System.Collections.Generic.IAsyncEnumerable.GetEnumerator() at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.d__1291.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()

The error can be removed in a few ways like:

  1. Placing the OrderBy after the Include
  2. Remove the Country projection.
@maumar
Copy link
Contributor Author

maumar commented Apr 5, 2017

The original issue is fixed in the current bits. Subsequent issues that were uncovered were fixed in c88b74f and f022d66

@maumar maumar closed this as completed Apr 5, 2017
@maumar maumar added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 5, 2017
@ajcvickers ajcvickers changed the title Query :: orderby + include + complex projection doesn't work Query: orderby + include + complex projection doesn't work May 9, 2017
@divega divega added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. and removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. labels May 10, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

No branches or pull requests

4 participants