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

Expression of type 'System.Collections.Generic.IEnumerable1 cannot be used for parameter of type System.Collections.Generic.IAsyncEnumerable1 #14812

Closed
Mortana89 opened this issue Feb 25, 2019 · 6 comments

Comments

@Mortana89
Copy link

Just finished upgrading all our Cosmos provider queries to the Async equivalent, and am getting the following exception on a very simple query:

var result = await _context.ExecutionParts.Include(x => x.ExecutionRun).SingleOrDefaultAsync(x => x.Id == executionPartId);
return result;

Stack trace:
System.ArgumentException: Expression of type 'System.Collections.Generic.IEnumerable`1[MeterProvider.Domain.Models.Aggregates.ExecutionRunAggregate.ExecutionStatusHistory]' cannot be used for parameter of type 'System.Collections.Generic.IAsyncEnumerable`1[MeterProvider.Domain.Models.Aggregates.ExecutionRunAggregate.ExecutionStatusHistory]' of method 'System.Linq.IOrderedQueryable`1[MeterProvider.Domain.Models.Aggregates.ExecutionRunAggregate.ExecutionStatusHistory] _ToQueryable[ExecutionStatusHistory](System.Collections.Generic.IAsyncEnumerable`1[MeterProvider.Domain.Models.Aggregates.ExecutionRunAggregate.ExecutionStatusHistory], Microsoft.EntityFrameworkCore.Query.QueryContext)'
Parameter name: arg0
   at System.Dynamic.Utils.ExpressionUtils.ValidateOneArgument(MethodBase method, ExpressionType nodeKind, Expression arguments, ParameterInfo pi, String methodParamName, String argumentParamName, Int32 index)
   at System.Linq.Expressions.Expression.Call(MethodInfo method, Expression arg0, Expression arg1)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ProjectionExpressionVisitor.VisitSubQuery(SubQueryExpression expression)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ProjectionExpressionVisitor.VisitUnary(UnaryExpression unaryExpression)
   at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ProjectionExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitBlockExpressions(ExpressionVisitor visitor, BlockExpression block)
   at System.Linq.Expressions.ExpressionVisitor.VisitBlock(BlockExpression node)
   at System.Linq.Expressions.BlockExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ExpressionVisitorBase.VisitLambda[T](Expression`1 node)
   at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ProjectionExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
   at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
   at Microsoft.EntityFrameworkCore.Query.ExpressionVisitors.ProjectionExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitSelectClause(SelectClause selectClause, QueryModel queryModel)
   at Remotion.Linq.QueryModelVisitorBase.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.VisitQueryModel(QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ExecuteAsync[TSource,TResult](MethodInfo operatorMethodInfo, IQueryable`1 source, LambdaExpression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.SingleOrDefaultAsync[TSource](IQueryable`1 source, Expression`1 predicate, CancellationToken cancellationToken)

Further technical details

EF Core version: 2.2.1
Database Provider: Cosmos DB
Operating system: Win10
IDE: Visual Studio 2017

@TomasHubelbauer
Copy link

I am using the version 3.0.0-preview4.19216.3 (also Cosmos) and it still seems to be happening.

@bdaniel7
Copy link

bdaniel7 commented May 30, 2019

I have the same error, only when calling SingleOrDefaultAsync().
When calling .ToListAsync(), it's not happening.

And when I'm using the non-async version, SingleOrDefault, I'm only getting a warning and lots of selects:

The LINQ expression 'where (new MeasureMessageThreadForEditDto() {
 Id = [item].Id, 
 Scope = [item].Scope,
 StartedByUserId = [item].StartedByUserId,
 StartedByUserFullName = [mt.StartedByUser].FullName,
 EventType = [item].EventType,
 Status = [item].Status,
 ScopeLevel = [item].ScopeLevel,
 SectionName = [item].SectionName,
 Messages = 
	{ from Message item in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[model.Message])
		where Not(Property([item], "IsDeleted"))
		where Not(Property([item], "IsDeleted"))
		join ApplicationUser m.Author in {from ApplicationUser item in value(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1[model.ApplicationUser]) 
											where Not(Property([item], "IsDeleted"))
											where Not(Property([item], "IsDeleted"))
											select [item]}
		on Property([item], "AuthorId") equals Property([m.Author], "Id") 
		where  ?= (Property([item], "Id") == Property([item], "MessageThreadId")) =?
		select new MessageDto() {
			Id = [item].Id,
			MessageThreadId = [item].MessageThreadId,
			Content = [item].Content,
			AuthorId = [item].AuthorId,
			AuthorFullName = [m.Author].FullName,
			DatePosted = [item].DatePosted,
			IsDeleted = [item].IsDeleted}
	}.ToList(),
	IsDeleted = [item].IsDeleted,
	LastEmailed = [item].LastEmailed}.Id == __id_0)'
	could not be translated and will be evaluated locally.

On EF Core 2.1, MS SQL 2017

@bdaniel7
Copy link

bdaniel7 commented May 30, 2019

I see that the warning and the error are caused by Mapster. When I'm using AutoMapper, it all works correctly.

@divega divega removed this from the 3.0.0 milestone Jun 24, 2019
@divega
Copy link
Contributor

divega commented Jun 24, 2019

Clearing milestone to discuss propose-close in regular triage.

@ajcvickers ajcvickers added verify-fixed This issue is likely fixed in new query pipeline. punted-for-3.0 and removed propose-close labels Jun 28, 2019
@ajcvickers ajcvickers added this to the Backlog milestone Jun 28, 2019
@ajcvickers ajcvickers removed the verify-fixed This issue is likely fixed in new query pipeline. label Jun 28, 2019
@smitpatel smitpatel removed their assignment Aug 7, 2019
@smitpatel
Copy link
Contributor

@Mortana89 - Can you share a repro project?
Include on cosmos works only for embedded owned navigations. In all other cases we would throw. See #16920

@smitpatel smitpatel removed this from the Backlog milestone Dec 9, 2019
@Mortana89
Copy link
Author

@Mortana89 - Can you share a repro project?
Include on cosmos works only for embedded owned navigations. In all other cases we would throw. See #16920

No sorry, it's been too long, we've switched to Cosmonaut somewhere in March and are using that in production now, so will be too difficult for me to repro now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants