When fetching an entity using the cache the entity state is "Detached" and not "Unchanged" as expected.
Steps to reproduce
A first call to
var product = _context.Product.Where(p => p.Id == request.ProductID).Cacheable(TimeSpan.FromMinutes(10)).FirstOrDefault();
var state = _context.Entry(product).State;
Has the result: "Unchanged"
The second call (using the cache) results in : "Detached" !
When using the product reference as relation, the next call to SaveChanges() fails as it tries to insert the entity a second time.
Further technical details
Using the cache in an asp.net core application with dependency injection
When fetching an entity using the cache the entity state is "Detached" and not "Unchanged" as expected.
Steps to reproduce
A first call to
Has the result: "Unchanged"
The second call (using the cache) results in : "Detached" !
When using the product reference as relation, the next call to SaveChanges() fails as it tries to insert the entity a second time.
Further technical details
Using the cache in an asp.net core application with dependency injection