SteffenMangold / EntityFrameworkCore.Cacheable

EntityFrameworkCore second level cache
Apache License 2.0
193 stars 27 forks source link

Entity state "Detached" #11

Open Henning34 opened 5 years ago

Henning34 commented 5 years ago

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