查询Entitiy Framework缓存

Moe*_*ald 5 c# entity-framework

是否可以对WhereEntity Framework缓存执行显式查询?我知道我可以用来Find在缓存中查找实体(基于实体主键).

代码示例:

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
Run Code Online (Sandbox Code Playgroud)

gre*_*k40 4

实体框架管理DbSet.Local. 它是一个可观察的集合,Where可以对其应用类似的 Linq 查询。它将包含加载的条目以及不同状态的条目,例如addedremoved直到SaveChanges被调用。