所以把它变成一个正式的答案:
框架将尝试缓存值(不是 IIS)。因此,请确保您没有将工作单元扩展到事务范围之外(即,将它用于相同的方法和检索方法)。此外,尝试重新建立存储/检索调用之间的上下文,这应该删除框架内可能发生的任何现有缓存。IE
[OperationContract]
public void Save(MyObject entity)
{
using (MyEntities db = new MyEntities())
{
db.MyObjects.Add(entity);
db.SaveChanges();
}
}
[OperationContract]
public MyObject Single(Int32 id)
{
using (MyEntities db = new MyEntities())
{
return db.MyObjects.Single(x => x.Id == id);
}
}
相对于:
[ServiceContract]
class MyService
{
private MyEntities db = new MyEntities();
[OperationContract]
public void Save(MyObject entity)
{
this.db.MyObjects.Add(entity);
this.db.SaveChanges();
}
[OperationContract]
public MyObjectFind(Int32 id)
{
return this.db.MyObjects.Single(x => x.Id == id);
}
}