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: Navigation filter + navigation group by + order by grouping key throws exception #7904

Closed
dvdobrovolskiy opened this issue Mar 16, 2017 · 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

@dvdobrovolskiy
Copy link

dvdobrovolskiy commented Mar 16, 2017

In general I have this error then using Telerik kendo grid with EF core when I try to use group by

I reproduced this behaviour in pure linq query

so model is

    public class Register
    {
        [Key]
        [ScaffoldColumn(false)]
        public int RegisterId { get; set; }

        public Person Teacher { get; set; }

        public Term Term { get; set; }

        public Level Level { get; set; }

        public List<Person> Students { get; set; }
    }

Person, Term, Level is also models

so this works

_context.Registers.Include(i => i.Teacher).Include(i => i.Term).Include(i => i.Level).Include(i => i.Students).GroupBy(g => g.Level.Title).OrderBy(o=>o.Key);

and this does not
_context.Registers.Include(i => i.Teacher).Include(i => i.Term).Include(i => i.Level).Include(i => i.Students).Where(w => w.Term.TermId == TermId).GroupBy(g => g.Level.Title).OrderBy(o=>o.Key);

Query with WHERE clause but without GROUPBY also works fine

exception itself

+		$exception	{System.ArgumentException: Property 'System.String Title' is not defined for type 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier`2[CETDB.Data.Register,System.Collections.Generic.IEnumerable`1[CETDB.Data.Level]]'
Parameter name: property
   at System.Linq.Expressions.Expression.Property(Expression expression, PropertyInfo property)
   at System.Linq.Expressions.Expression.MakeMemberAccess(Expression expression, MemberInfo member)
   at System.Linq.Expressions.MemberExpression.Update(Expression expression)
   at System.Linq.Expressions.ExpressionVisitor.VisitMember(MemberExpression node)
   at System.Linq.Expressions.MemberExpression.Accept(ExpressionVisitor visitor)
   at Remotion.Linq.Parsing.ExpressionVisitors.ReplacingExpressionVisitor.Visit(Expression expression)
   at Microsoft.EntityFrameworkCore.Query.Expressions.Internal.NullConditionalExpression.VisitChildren(ExpressionVisitor visitor)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MemberAccessBindingExpressionVisitor.VisitExtension(Expression node)
   at System.Linq.Expressions.Expression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.ReplaceClauseReferences(Expression expression, IQuerySource querySource, Boolean inProjection)
   at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleGroup(EntityQueryModelVisitor entityQueryModelVisitor, GroupResultOperator groupResultOperator, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.ResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.RelationalResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection`1 resultOperators, QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.LiftSubQuery(IQuerySource querySource, Expression itemsExpression, Expression expression)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](Expression query, INodeTypeProvider nodeTypeProvider, IDatabase database, ILogger logger, Type contextType)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass19_0`1.<CompileQuery>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Remotion.Linq.QueryableBase`1.System.Collections.IEnumerable.GetEnumerator()
   at Kendo.Mvc.Extensions.QueryableExtensions.Execute[TModel,TResult](IQueryable source, Func`2 selector)
   at Kendo.Mvc.Extensions.QueryableExtensions.CreateDataSourceResult[TModel,TResult](IQueryable queryable, DataSourceRequest request, ModelStateDictionary modelState, Func`2 selector)
   at Kendo.Mvc.Extensions.QueryableExtensions.ToDataSourceResult(IQueryable queryable, DataSourceRequest request)
   at CETDB.Controllers.AdministrationController.Registers_Read(DataSourceRequest request, Int32 TermId) in C:\Users\dima\documents\visual studio 2017\Projects\CETDB\CETDB\Controllers\AdministrationController.cs:line 325
   at lambda_method(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__27.MoveNext()}	System.ArgumentException

Update
if I split this query to

            var xxx = await _context.Registers.Include(i => i.Teacher).Include(i => i.Term).Include(i => i.Level).Include(i => i.Students).Where(w => w.Term.TermId == TermId).ToListAsync();
            var yyy = xxx.GroupBy(g => g.Level.Title).OrderBy(o=>o.Key);

all works fine

@ajcvickers ajcvickers added this to the 2.0.0 milestone Mar 17, 2017
@smitpatel
Copy link
Member

smitpatel commented Mar 23, 2017

This happens in 1.1.1 release but fixed in latest dev.
This is the SQL generated.

SELECT [i0].[RegisterId], [i0].[LevelId], [i0].[TeacherPersonId], [i0].[TermId], [i.Level0].[Title]
FROM [Registers] AS [i0]
LEFT JOIN [Levels] AS [i.Level0] ON [i0].[LevelId] = [i.Level0].[LevelId]
LEFT JOIN [Terms] AS [i.Term0] ON [i0].[TermId] = [i.Term0].[TermId]
WHERE [i.Term0].[TermId] = @__termId_0
ORDER BY [i.Level0].[Title]

@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 Mar 23, 2017
@smitpatel smitpatel changed the title "Property 'Int32 LevelId' is not defined for type 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier Query: Navigation filter + navigation group by + order by grouping key throws exception Mar 23, 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