session.Evict 清除查询结果集的缓存

  public TEntity FindSingleByExpression(Expression<Func<TEntity, bool>> expression)
        {
            var session = this.OpenSession();

            //   session.Clear();   //session.Evict(entity);有时会不起作用, session.Clear(); 反而可以代研究 

            var entity = session.Linq<TEntity>().FirstOrDefault(expression);
            session.Evict(entity);
            return entity;
        }

 

 public void Evict(TEntity entity)
        {
            using (var session = this.OpenSession())
            {
               session.Evict(entity);
            }
        }

session.Evict 清除查询结果集的缓存。

posted @ 2012-08-07 15:51  多远才是未来  阅读(258)  评论(0编辑  收藏  举报