VahidN / EFSecondLevelCache.Core

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

Problem faced in q.cachable(debuginfo) #23

Closed santubangalore closed 5 years ago

santubangalore commented 5 years ago

Summary of the issue

        q.Cacheable(debugInfo) throws error.

If I remove the q.Cacheable(debuginfo) line, the error vanishes. The application is running without any issues without this line. When we include this line, the error starts.

Environment

The in-use version:
Operating system:  windows 10 professional
IDE: (e.g. Visual Studio 2015) :VS 2017 Pro

Example code/Steps to reproduce:

the query() method joins two tables and contains a include statement (query1.include(query))
paste your core code
var q = from c in this.Query()
                where c.Buid == buid
                orderby c.Buid
                select c;
        var debugInfo = new EFCacheDebugInfo();
        debugInfo.EFCacheKey = new EFCacheKey();

        var temp = debugInfo.IsCacheHit;
        q.Cacheable(debugInfo);
        return await q.ToListAsync();

Output:

Exception message:
Full Stack trace:
  at EFSecondLevelCache.Core.EFCachedQueryProvider`1.Materialize(Expression expression, Func`1 materializer)
   at EFSecondLevelCache.Core.EFCachedQueryable`1.System.Collections.Generic.IEnumerable<TType>.GetEnumerator()
   at EFSecondLevelCache.Core.EFCachedQueryable`1.get_AsyncEnumerable()
   at Microsoft.EntityFrameworkCore.Extensions.Internal.QueryableExtensions.AsAsyncEnumerable[TSource](IQueryable`1 source)
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
VahidN commented 5 years ago

Hopefully your this.Query() returns an IQueryable. It should be q = q.Cacheable(debugInfo); instead of q.Cacheable(debugInfo); alone, to chain LINQ commands correctly or just try:

return await (from c in this.Query()
                where c.Buid == buid
                orderby c.Buid
                select c).Cacheable().ToListAsync();
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.