은 다음과 같이 진행됩니다이상한 행동
MyDbContext ctx = new MyDbContext();
IFooRepository repo = new FooRepository(ctx);
var items = repo.GetAvailableItem().ToList(); //this will query all item.sold = false.
// here it returns three rows
foreach(var item in items) {
item.sold = true;
}
repo.commit(); // this will call the SaveChanges() in DbContext
Thread.sleep(10000)
// Now I quickly execute a query in SQL Server Management Studio
// UPDATE Item SET Sold = 0;
var items02 = repo.GetAvailableItem().ToList(); // this will query all item.sold = false.
// here items02 also contains three rows
// HOWEVER, when I watch the value of item.sold in items02, it is all True
이 디자인에 의해 행동인가?
왜? 그것은 DbContext가 엔티티를 캐시하고 동일한 쿼리를 다시 실행하더라도 결코 리프레시되지 않기 때문입니까?
public IQueryable<Item> GetAvailableItem()
{
var items = from x in DbContext.Item
where x.Sold == 0
select x;
return items;
}
public virtual int Commit()
{
return DbContext.SaveChanges();
}
이'GetAvailableItem을()'게시'()'방법을 커밋하십시오 참조하십시오. 커밋에 뭔가 이상한 것 같습니다. –