5
是否可以在Entity Framework缓存上执行明确的Where
查询?我知道我可以使用Find
在缓存中查找实体(基于实体主键)。查询Entitiy框架缓存
代码示例:
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
你可能想利用'bSet.Local' – grek40
'DbSet.Local'文档:https://msdn.microsoft.com/en-us/library/gg696248(v=vs.113).aspx –
@ grek40](http://stackoverflow.com/users/5265292/grek40):感谢您的评论'DbSet.Local'完成了这项工作。请发表您的评论作为答案! – Moerwald