title: How do I keep an IQueryable<> within a transaction using the repository pattern?
body: <p>According to NHProf, the use of implicit transactions is discouraged:</p>
  
  <p><a href="http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions" rel="noreferrer"><a href="http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions" rel="noreferrer">http://nhprof.com/Learn/Alerts/DoNotUseImplicitTransactions</a></a></p>
  
  <p>However, NHibernate LINQ returns an <code>IQueryable&lt;&gt;</code> when reading objects from the database, and this is lazily evaluated. I have this method in a repository:</p>
  
  <pre><code>public IQueryable&lt;T&gt; GetAll&lt;T&gt;()
  {
      using (var transaction = _session.BeginTransaction())
      {
          var data = _session.Linq&lt;T&gt;();
          transaction.Commit();
          return data;
      }
  }
  </code></pre>
  
  <p>The issue here is that the method will commit the transaction before <code>data</code> is evaluated. Is there a way to use the repository pattern and keep the <code>IQueryable&lt;&gt;</code> in an explicit transaction? Or is it acceptable for read operations to use implicit transactions?</p>