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: Property '...' is not defined for type for GroupBy with projection and ordering #7740

Closed
CSerX opened this issue Feb 28, 2017 · 4 comments
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

@CSerX
Copy link

CSerX commented Feb 28, 2017

I am try use some select and group by, like this:

var tempData = DataContext.TableA
	.Select(r => new { TableB_Name = r.TableB.Name, TableC_Name = r.TableC.Name, r.id, r.dateTime })
	.GroupBy(r => r.TableB_Name)
	.OrderBy(r => r.Key)
	.ToList();

Model:

public partial class TableA
{
	[Key]
	public Int64 id { get; set; }
	public DateTime dateTime { get; set; }
	public Int64 refTableB { get; set; }
	public Int64? refTableC { get; set; }

	[ForeignKey("refTableB")]
	public TableB TableB { get; set; }

	[ForeignKey("refTableC")]
	public TableC TableC { get; set; }
}

Running the code will throw following error:

Property 'System.String Name' is not defined for type 'Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor+TransparentIdentifier2[Microsoft.EntityFrameworkCore.Storage.ValueBuffer,System.Collections.Generic.IEnumerable1[TestProject.Models.TableC]]'
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 System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Remotion.Linq.Parsing.ExpressionVisitors.ReplacingExpressionVisitor.Visit(Expression expression)
at Remotion.Linq.Parsing.ExpressionVisitors.ReplacingExpressionVisitor.Replace(Expression replacedExpression, Expression replacementExpression, Expression sourceTree)
at Microsoft.EntityFrameworkCore.Query.Expressions.Internal.NullConditionalExpression.VisitChildren(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.VisitExtension(Expression node)
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 System.Linq.Expressions.ExpressionVisitor.Visit(ReadOnlyCollection1 nodes) at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.Internal.MemberAccessBindingExpressionVisitor.VisitNew(NewExpression expression) at System.Linq.Expressions.NewExpression.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.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel) at Remotion.Linq.Clauses.SelectClause.Accept(IQueryModelVisitor visitor, 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.RelationalQueryModelVisitor.VisitSubQueryModel(QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.LiftSubQuery(IQuerySource querySource, Expression itemsExpression, Expression expression) at Microsoft.EntityFrameworkCore.Query.RelationalQueryModelVisitor.CompileMainFromClauseExpression(MainFromClause mainFromClause, QueryModel queryModel) at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) at Remotion.Linq.Clauses.MainFromClause.Accept(IQueryModelVisitor visitor, 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) 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() 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_01.b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func1 compiler) at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Remotion.Linq.QueryableBase1.GetEnumerator() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at TestProject.Controllers.TestController.Index() in D:\Projects\Research\TestProject\GeneratedController\TestController.cs:line 31
at lambda_method(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__27.MoveNext()

If remove "TableC_Name = r.TableC.Name" it run successfull
or if change type of field:
Int64? refTableC { get; set; }
to:
Int64 refTableC { get; set; }
then run successfull

@rowanmiller rowanmiller added this to the 2.0.0 milestone Mar 3, 2017
@maumar
Copy link
Contributor

maumar commented Apr 1, 2017

This is fixed in current bits. We produce the following query (group by operation is done on the client):

SELECT [r.TableB0].[Name], [r.TableC0].[Name], [r0].[id], [r0].[dateTime]
FROM [TableAs] AS [r0]
LEFT JOIN [TableCs] AS [r.TableC0] ON [r0].[refTableC] = [r.TableC0].[Id]
INNER JOIN [TableBs] AS [r.TableB0] ON [r0].[refTableB] = [r.TableB0].[Id]
ORDER BY [r.TableB0].[Name]

@maumar maumar closed this as completed Apr 1, 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 1, 2017
@ajcvickers ajcvickers changed the title Property '...' is not defined for type Query: Property '...' is not defined for type for GroupBy with projection and ordering 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
@mikebridge
Copy link

Are there plans to fix this for 1.1 as well?

@dguisinger
Copy link

Is there a work around?

@maumar
Copy link
Contributor

maumar commented May 23, 2017

@mikebridge no plans to fix this for 1.1 patch, the change that made this work is very significant and is too risky for a patch release, given the impact.

@dguisinger try executing groupby/orderby on the client, like so:

var tempData = DataContext.TableA
	.Select(r => new { TableB_Name = r.TableB.Name, TableC_Name = r.TableC.Name, r.id, r.dateTime })
	.ToList();
	.GroupBy(r => r.TableB_Name)
	.OrderBy(r => r.Key)
	.ToList();

It's essentially what we do in current bits anyway.

@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

7 participants