VahidN / EFSecondLevelCache.Core

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

Just want to discuss improvement which i might be able to contribute #63

Closed Rayvid closed 4 years ago

Rayvid commented 4 years ago

Summary of the issue

Thanks for a great library, I want to contribute to making it even greater.

I just want to make working with Microsoft.EntityFrameworkCore.Proxies more fluent. At the moment Cacheable appends AsNoTracking on originated query by default and to actually load inner properties when using Cacheable you need to do some magic as I did in a query I have provided as a sample

So the idea would be to add Include and ThenInclude extensions to EFCachedQueryable, what do you think?

And not sure if it's possible, to deproxy Entities automatically? Because if not you need to use optionsBuilder.ConfigureWarnings(e => e.Ignore(CoreEventId.DetachedLazyLoadingWarning)); to it to work

Environment

.NET Core SDK version: all
Microsoft.EntityFrameworkCore version: 3.1
EFSecondLevelCache.Core version: 2.9

Example code/Steps to reproduce:

                    from rebate in _context.MMSRebates.Include(_ => _.FixedRebates).Include(_ => _.VariableRebates).Include(_ => _.IncentiveRebates)
                    from cust in _context.Customers.Where(_ => _.AcquirerId == acquirerID)
                        join hog in _context.MerchantGroupHOes on cust.Id equals hog.CustomerId
                        join merc in _context.Stores.Where(_ => _.IsActive) on hog.Id equals merc.MerchantGroupId
                    where merc.Id == rebate.EntityId || hog.Id == rebate.EntityId || cust.Id == rebate.EntityId
                    select new { Rebate = rebate, rebate.FixedRebates, rebate.VariableRebates, rebate.IncentiveRebates })
                        .Cacheable().ToList()
                        .Select(_ =>
                        {
                            var result = _.Rebate;
                            result.FixedRebates = _.FixedRebates;
                            result.VariableRebates = _.VariableRebates;
                            result.IncentiveRebates = _.IncentiveRebates;
                            return result;
                        });
VahidN commented 4 years ago
Rayvid commented 4 years ago

Hi, well I'm in the situation getting hands-on on the project already using proxies and i managed to integrate your lib using that not very nice way I have illustrated with a code snippet. Don't you agree if to use Microsoft.EntityFrameworkCore.Proxies - you get detached proxies after Cacheable() call and need to use optionsBuilder.ConfigureWarnings(e => e.Ignore(CoreEventId.DetachedLazyLoadingWarning)); and would be nice to have capability to "autodeproxy" those

Rayvid commented 4 years ago

Ok never mind, I found EFCore backlog where they plan to introduce conditional proxy creation prevention, I guess that will solve that kind of problems, no need to change this library to support proxies