VahidN / EFSecondLevelCache.Core

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

Cannot cast EFCachedQueryable to IOrderedQueryable #42

Closed Rayvid closed 4 years ago

Rayvid commented 4 years ago

Summary of the issue

Message: System.InvalidCastException : Unable to cast object of type 'EFSecondLevelCache.Core.EFCachedQueryable1[Whatever.Model.PricingEntities.PriceCalculationParameter]' to type 'System.Linq.IOrderedQueryable1[Whatever.Model.PricingEntities.PriceCalculationParameter]'.

Environment

All

Example code/Steps to reproduce:

        var priceCalculationParameters = await pricingContext.PriceCalculationParameters.Cacheable()
            .Where(x => x.PricingId == currentPricing.PricingId)
            .OrderBy(x => x.PriceValidityIntervals.Min(y => y.Start))
            .ToListAsync().ConfigureAwait(false);

Output:

Test Name: CalculateRoughReservedEndTime_WithReservedAmountAndStartingWithinPaidTimeInterval_ShouldReturnTheSameEndTime(Monday) Test FullName: Whatever.Backend.Tests.Service.PriceCalculationServiceTests.CalculateRoughReservedEndTime_WithReservedAmountAndStartingWithinPaidTimeInterval_ShouldReturnTheSameEndTime(Monday) Test Source: C:\Users\gkisonas\Projects\Whatever\Whatever.Backend.Tests\Service\PriceCalculationServiceTests.cs : line 2824 Test Outcome: Failed Test Duration: 0:00:07.111

Result StackTrace:
at System.Linq.Queryable.OrderBy[TSource,TKey](IQueryable1 source, Expression1 keySelector) at Whatever.Backend.Services.PriceCalculationService.d46.MoveNext() in C:\Users\gkisonas\Projects\Whatever\Whatever.Backend\Services\PriceCalculationService.cs:line 934 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at Whatever.Backend.Tests.Service.PriceCalculationServiceTests.d71.MoveNext() in C:\Users\gkisonas\Projects\Whatever\Whatever.Backend.Tests\Service\PriceCalculationServiceTests.cs:line 2841 --- End of stack trace from previous location where exception was thrown --- at NUnit.Framework.Internal.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult) at NUnit.Framework.Internal.Commands.TestMethodCommand.RunAsyncTestMethod(TestExecutionContext context) Result Message: System.InvalidCastException : Unable to cast object of type 'EFSecondLevelCache.Core.EFCachedQueryable1[Whatever.Model.PricingEntities.PriceCalculationParameter]' to type 'System.Linq.IOrderedQueryable1[Whatever.Model.PricingEntities.PriceCalculationParameter]'.

VahidN commented 4 years ago

Which version? Have you tried adding the Cacheable() method before the ToListAsync() method?

Rayvid commented 4 years ago

Cacheable after OrderBy works, thanks. So in general pattern is to put Cacheable after last IQueryable? What will be cached then, only filtered data got to this point? Or statement works like key - cache will work only for same statement?

VahidN commented 4 years ago

yes, yes, yes!

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.