【问题标题】:NHibernate Second Level Cache With NHibernate Linq Provider 1.0NHibernate 二级缓存与 NHibernate Linq Provider 1.0
【发布时间】:2009-09-03 18:51:31
【问题描述】:

如何使用 NHibernate Linq Provider 1.0 启用 NHibernate 二级缓存?

二级缓存似乎只适用于 ICriteria 用法。

【问题讨论】:

    标签: c# linq nhibernate


    【解决方案1】:

    是的,我终于解决了这个问题:

    public IQuerable<T> CreateLinqQuery()
    {
        var query = session.Linq<T>();
        query.QueryOptions.SetCachable(true);
        return query;
    }
    

    更新 正如其他人指出的那样,在 NH3 中,使用 query.Cacheable()。 但是要非常小心地这样做:

    // Correct way:
    query = query.Cacheable();
    
    // This won't work:
    query.Cacheable();
    

    【讨论】:

    • 谢谢cbp,我去看看
    【解决方案2】:

    对于 NHibernate 3+,它是 session.Query&lt;T&gt;().Cacheable()

    【讨论】:

      【解决方案3】:

      NH3 RC 版本:

      public IQueryable<T> Queryable<T>()
      {
          IQueryable<T> queryable = SessionFactory.OpenSession().Queryable<T>();
          queryable = queryable.Cacheable<T>();
      
          return queryable;
      }
      

      【讨论】:

        猜你喜欢
        • 2011-09-02
        • 2011-06-19
        • 1970-01-01
        • 1970-01-01
        • 2011-10-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-26
        相关资源
        最近更新 更多