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

Getting InvalidCastException when grouping over a projection #1909

Closed
rkonstantinov opened this issue Mar 26, 2015 · 1 comment
Closed

Getting InvalidCastException when grouping over a projection #1909

rkonstantinov opened this issue Mar 26, 2015 · 1 comment
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

@rkonstantinov
Copy link

I'm not sure if this has been already addressed or not. I'm testing it with Beta 3 version.

The following code:

var db = new SampleContext();
var result = db.Blogs
    .Select(x => new { x.BlogId })
    .GroupBy(x => x.BlogId);
result.ToList();

is producing InvalidCastException:

System.InvalidCastException: Unable to cast object of type 'Microsoft.Data.Entity.Query.QuerySourceScope`1[<>f__AnonymousType0`1[System.Int32]]' to type 'Microsoft.Data.Entity.Query.QuerySourceScope`
   at Microsoft.Data.Entity.Query.QuerySourceScope.GetResult[TResult](IQuerySource querySource)

Here is the context and model declaration:

    public class SampleContext : DbContext
    {
        public DbSet<Blog> Blogs { get; set; }      

        protected override void OnConfiguring(DbContextOptions builder)
        {
            builder.UseSqlServer(@"Server=(localdb)\v11.0;Database=Samples;Trusted_Connection=True;");
        }
    }

    public class Blog
    {
        public int BlogId { get; set; }     
    }
@rowanmiller
Copy link
Contributor

Confirmed this still repros on the latest bits (though with a different exception)

Unhandled Exception: System.ArgumentException: Expression of type 'System.Func`2[Microsoft.Data.Entity.Storage.ValueBuffer,System.Int32]' cannot be used for parameter of type 'System.Func`2[<>f__AnonymousType0`
1[System.Int32],System.Int32]' of method 'System.Collections.Generic.IEnumerable`1[System.Linq.IGrouping`2[System.Int32,<>f__AnonymousType0`1[System.Int32]]] _GroupBy[<>f__AnonymousType0`1,Int32,<>f__AnonymousT
ype0`1](System.Collections.Generic.IEnumerable`1[<>f__AnonymousType0`1[System.Int32]], System.Func`2[<>f__AnonymousType0`1[System.Int32],System.Int32], System.Func`2[<>f__AnonymousType0`1[System.Int32],<>f__Ano
nymousType0`1[System.Int32]])'
   at System.Linq.Expressions.Expression.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arg, ParameterInfo pi)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0, Expression arg1, Expression arg2)
   at Microsoft.Data.Entity.Query.ResultOperatorHandler.HandleGroup(EntityQueryModelVisitor entityQueryModelVisitor, GroupResultOperator groupResultOperator, QueryModel queryModel)
   at Microsoft.Data.Entity.Query.ResultOperatorHandler.<>c.<.cctor>b__25_9(EntityQueryModelVisitor v, ResultOperatorBase r, QueryModel q)
   at Microsoft.Data.Entity.Query.ResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
   at Microsoft.Data.Entity.Query.Internal.RelationalResultOperatorHandler.HandlerContext.EvalOnClient(Boolean requiresClientResultOperator)
   at Microsoft.Data.Entity.Query.Internal.RelationalResultOperatorHandler.HandleGroup(HandlerContext handlerContext)
   at Microsoft.Data.Entity.Query.Internal.RelationalResultOperatorHandler.HandleResultOperator(EntityQueryModelVisitor entityQueryModelVisitor, ResultOperatorBase resultOperator, QueryModel queryModel)
   at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
   at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitResultOperator(ResultOperatorBase resultOperator, QueryModel queryModel, Int32 index)
   at Remotion.Linq.QueryModelVisitorBase.VisitResultOperators(ObservableCollection`1 resultOperators, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.Data.Entity.Query.RelationalQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.Data.Entity.Query.Internal.SqlServerQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.Data.Entity.Query.EntityQueryModelVisitor.CreateQueryExecutor[TResult](QueryModel queryModel)
   at Microsoft.Data.Entity.Storage.Database.CompileQuery[TResult](QueryModel queryModel)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.<>c__DisplayClass19_0`1.<CompileQuery>b__0()
   at Microsoft.Data.Entity.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.CompileQuery[TResult](Expression query)
   at Microsoft.Data.Entity.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.Data.Entity.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at Remotion.Linq.QueryableBase`1.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

@rowanmiller rowanmiller modified the milestones: 7.0.0-rc2, 7.0.0 Dec 10, 2015
@mikary mikary assigned mikary and unassigned maumar Jan 4, 2016
@mikary mikary closed this as completed in 9f47f13 Jan 7, 2016
@mikary mikary added the 2 - Done label Jan 7, 2016
@mikary mikary mentioned this issue Mar 4, 2016
@ajcvickers ajcvickers removed this from the 1.0.0-rc2 milestone Oct 15, 2022
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Oct 15, 2022
@ajcvickers ajcvickers added this to the 1.0.0 milestone 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

5 participants