zzzprojects / EntityFramework-Plus

Entity Framework Plus extends your DbContext with must-haves features: Include Filter, Auditing, Caching, Query Future, Batch Delete, Batch Update, and more
https://entityframework-plus.net/
MIT License
2.28k stars 318 forks source link

IncludeOptimized and Cache don't work together. #631

Open gizadirov opened 4 years ago

gizadirov commented 4 years ago

Description

var projects = dbContext.Projects
                        .IncludeOptimized(x => x.Sites)
                        .FromCache("projects");

//schematic model:
class Projects {
   List<Site> Sites;
}
class Site {
  Guid SiteID;
  Guid ProjectID;
  Project Project;
}

Exception

Exception message: Field '_queryCompiler' defined on type 'Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider' is not a field on the target object which is of type 'Z.EntityFramework.Plus.QueryIncludeOptimizedProvider`1[DBModel.Project]'.

Stack trace: at System.Reflection.RtFieldInfo.GetValue(Object obj) in /_/src/System.Private.CoreLib/src/System/Reflection/RtFieldInfo.cs:line 178
   at .(IQueryable , RelationalQueryContext& , QuerySqlGenerator& )
   at Z.EntityFramework.Plus.QueryCacheManager.GetCacheKey(IQueryable query, String[] tags)
   at Z.EntityFramework.Plus.QueryCacheExtensions.FromCache[T](IQueryable`1 query, MemoryCacheEntryOptions options, String[] tags)
   at Z.EntityFramework.Plus.QueryCacheExtensions.FromCache[T](IQueryable`1 query, String[] tags)

Further technical details

JonathanMagnan commented 4 years ago

Hello @gizadirov ,

Thank you for reporting, we successfully reproduced the issue.

We will look if we can make both features work together.

Best Regards,

Jon


Performance Libraries context.BulkInsert(list, options => options.BatchSize = 1000); Entity Framework ExtensionsEntity Framework ClassicBulk OperationsDapper Plus

Runtime Evaluation Eval.Execute("x + y", new {x = 1, y = 2}); // return 3 C# Eval FunctionSQL Eval Function

JonathanMagnan commented 4 years ago

Hello @gizadirov ,

We tried to make it work but unfortunately, the IncludeOptimized requires a ChangeTracker to work correctly and the Cache feature requires to don't use a ChangeTracker since entities returned cannot be dependent from a Context.

So at this moment, there is nothing we can do for it ;(

Best Regards,

Jon