Is it possible to perform an explicit Where
query on the Entity Framework cache? I know that I can use Find
to look for an entity in the cache (based on the entities primary key).
Code sample:
var person = new PersonToStoreInDb() { Id = 1, Name = "John" };
dbSet.Add(person);
// Perform some other code
...
// DbContext.SaveChanges was NOT called!
var personFromDbSet = bSet.Where(p => p.Name == "John").First();
// personFromDbSet is null because it was not sent towards DB via SaveChanges
Entity Framework manages the cached data in DbSet.Local
. It is an observable collection and Linq queries like Where
can be applied to it. It will contain the loaded entries as well as entries of different state like added
and removed
until SaveChanges
is called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With