zzzprojects / EntityFramework-Classic

Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
https://entityframework-classic.net
Other
103 stars 27 forks source link

Error when trying to using Cache for executing a store procedure #3

Closed ivantran85 closed 5 years ago

ivantran85 commented 5 years ago

Hi Team, I am trying to use Cache for a result from a store procedure like this

var employerInfo = _context.usp_get_cpr_employer_info(data.Identifier, data.PolicyId).AsQueryable().Cache().SingleOrDefault();

And I got an error below

System.Exception: Oops! The ObjectQuery cannot be found. Please use an explice key or report this issue here: https://github.com/zzzprojects/EntityFramework-Classic/issues at Z.EntityFramework.Classic.QueryCacheManager.GetCacheKey(IQueryable query)

Could you please help to fix it

Thanks so much

JonathanMagnan commented 5 years ago

Hello @ivantran85 ,

Adding AsQueryable doesn't work as that's not a context query.

However, it's possible for you to still cache this kind of query using your own cache key.

For example:

var employerInfo = _context.usp_get_cpr_employer_info(data.Identifier, data.PolicyId).Cache("myCacheKey").SingleOrDefault();

Let me know if that solution work for you.

Best Regards,

Jonathan

JonathanMagnan commented 5 years ago

Hello @ivantran85 ,

This issue will be closed since it has been answered.

Feel free to reopen it if you feel otherwise.

Best Regards,

Jonathan