8
据我所知实体框架实现了身份映射模式,因此EF缓存内存中的一些实体。如何使实体框架无效4内部缓存
让我给你举例。
var context = new StudentContext();
var student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// any way of changing student in DB
var anotherContext = new StudentContext();
var anotherStudent = anotherContext.Students.Where(st => st.Id == 34).FirstOrDefault();
anotherStudent.Name = "John Smith";
anotherContext.SaveChanges();
student = context.Students.Where(st => st.Id == 34).FirstOrDefault();
// student.Name contains old value
有什么办法无效第一上下文的缓存,而无需重新创建上下文检索新student
实体?
感谢您的帮助。