EntityFramework object cache. Getting already found objects

When Distortion Tracking is on, EF remembers all received objects. Is there some other way to tell EF not to query the DB for the object and search its local cache? I know that the GetObjectByKey method looks for an object in memory and only after that in the database.

+2
entity-framework


source to share


1 answer


You can request ObjectStateManager

:



var entities = context.ObjectStateManager()
                      .GetObjectStateEntries(~EntityState.Detached) // All attached entities
                      .Where(e => !e.IsRelationship)
                      .Select(e => e.Entity)
                      .OfType<YourEntityType>()
                      .Where(...);

      

+3


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics