VahidN / EFSecondLevelCache.Core

Entity Framework Core Second Level Caching Library
Apache License 2.0
326 stars 50 forks source link

using EF Core 3.0: bugs in async cached query #46

Closed hez2010 closed 5 years ago

hez2010 commented 5 years ago

Summary of the issue

System.ArgumentException: Expression of type 'TestEntity' cannot be used for return type 'System.Threading.Tasks.Task`1[TestEntity]'

Environment

The in-use version: 2.5.1
Operating system: Windows 10
IDE: Visual Studio 2019

Example code/Steps to reproduce:

await xxx.Cacheable().FirstOrDefaultAsync();

Output:

System.ArgumentException: Expression of type 'TestEntity' cannot be used for return type 'System.Threading.Tasks.Task`1[TestEntity]'
   at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection`1 parameters, String paramName)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable`1 parameters)
   at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters)
   at Microsoft.EntityFrameworkCore.Query.Pipeline.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
   at EFSecondLevelCache.Core.EFCachedQueryProvider`1.<>c__DisplayClass10_0`1.<Execute>b__0()
   at EFSecondLevelCache.Core.EFCachedQueryProvider`1.Materialize(Expression expression, Func`1 materializer)
   at EFSecondLevelCache.Core.EFCachedQueryProvider`1.Execute[TResult](Expression expression)
   at EFSecondLevelCache.Core.EFCachedQueryProvider`1.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, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.FirstOrDefaultAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
VahidN commented 5 years ago

Fixed it via#https://github.com/VahidN/EFSecondLevelCache.Core/commit/4ebfa217971067d45a4282b1729c6beeca909d7e

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related problems.