C#查询可以在上下文中独立更改
我有一个难题。我已经看到,查询中的记录数可以更改,而无需重新运行相同的查询。 下面的代码显示了该场景:C#查询可以在上下文中独立更改,c#,.net,linq,entity-framework,orm,C#,.net,Linq,Entity Framework,Orm,我有一个难题。我已经看到,查询中的记录数可以更改,而无需重新运行相同的查询。 下面的代码显示了该场景: using (var db = new MyContext()) { var query = from e in db.Entities select e; //here the query.Count is equals to 100 for example Thread.Sleep(10000); //after some times the db h
using (var db = new MyContext()) {
var query = from e in db.Entities select e;
//here the query.Count is equals to 100 for example
Thread.Sleep(10000);
//after some times the db has been populated
//here the query.Count is equals to 200 for example without run again the query
}
我的问题是:为什么会有这种行为?为什么它似乎是查询结果和数据层之间的自动绑定?实体框架在后台工作以更新查询结果?
提前感谢。请记住,使用IQueryable,由于,每次枚举数据库时,即运行
.Count()
,.ToList()
等时,都会对该数据库计算和执行查询
如果有疑问,请使用探查器(如或)准确了解您何时访问数据库。我不确定我是否完全理解您的问题,但我相信答案是肯定的