VahidN / EFSecondLevelCache.Core

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

Breaking changes regarding efcore 3.0.0 type: ExpressionPrinter #48

Closed kooshanabedian closed 5 years ago

kooshanabedian commented 5 years ago

Summary of the issue

Migrating to dotnetcore 3 (preview 8) from version 2.2, seems to break caching.

Environment

.NET Core SDK version: 3.0.0-preview8.19405.11
Microsoft.EntityFrameworkCore version: 3.0.0.0
EFSecondLevelCache.Core version: 2.6.1

Example code/Steps to reproduce:

public static async Task<IPagedList<T>> ToPagedListAsync<T>(this IQueryable<T> source, int pageIndex, int pageSize, int indexFrom = 0, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (indexFrom > pageIndex)
            {
                throw new ArgumentException($"indexFrom: {indexFrom} > pageIndex: {pageIndex}, must indexFrom <= pageIndex");
            }

            var count = await source.CountAsync(cancellationToken).ConfigureAwait(false);
            var items = await source.Skip((pageIndex - indexFrom) * pageSize)
                                    .Take(pageSize)
                                    .Cacheable<T>()
                                    .ToListAsync(cancellationToken).ConfigureAwait(false);

            var pagedList = new PagedList<T>()
            {
                PageIndex = pageIndex,
                PageSize = pageSize,
                IndexFrom = indexFrom,
                TotalCount = count,
                Items = items,
                TotalPages = (int)Math.Ceiling(count / (double)pageSize)
            };

            return pagedList;
        }

Output:

Exception message: An unhandled exception occurred while processing the request.
TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter' from assembly 'Microsoft.EntityFrameworkCore, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

EFSecondLevelCache.Core.EFCacheKeyProvider.GetEFCacheKey<T>(IQueryable<T> query, Expression expression, string saltKey)

Full Stack trace:

EFSecondLevelCache.Core.EFCacheKeyProvider.GetEFCacheKey<T>(IQueryable<T> query, Expression expression, string saltKey)
EFSecondLevelCache.Core.EFCachedQueryProvider<TType>.Materialize(Expression expression, Func<object> materializer)
EFSecondLevelCache.Core.EFCachedQueryable<TType>.GetAsyncEnumerator(CancellationToken cancellationToken)
System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable<T>.GetAsyncEnumerator()
Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync<TSource>(IQueryable<TSource> source, CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.IQueryablePageListExtensions.ToPagedListAsync<T>(IQueryable<T> source, int pageIndex, int pageSize, int indexFrom, CancellationToken cancellationToken) in IQueryablePageListExtensions.cs
VahidN commented 5 years ago

Fixed it via#https://github.com/VahidN/EFSecondLevelCache.Core/commit/80d0418b8256a7f472c65f526d8f0ea3b0749aab

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.