title: How do I refactor three database operations that only differ by the method call?
body: <p>I have three database operations like so:</p>
  
  <pre><code>public void Add&lt;T&gt;(T entity)
  {
      using (var transaction = Session.BeginTransaction())
      {
          if (entity is IEnumerable)
          {
              foreach (var item in (IEnumerable) entity)
              {
                  Session.Save(item);
              }
          }
          else
          {
              Session.Save(entity);
          }
  
          transaction.Commit();
      }
  }
  
  public void Update&lt;T&gt;(T entity)
  {
      using (var transaction = Session.BeginTransaction())
      {
          if (entity is IEnumerable)
          {
              foreach (var item in (IEnumerable) entity)
              {
                  Session.Update(item);
              }
          }
          else
          {
              Session.Update(entity);
          }
  
          transaction.Commit();
      }
  }
  
  public void Delete&lt;T&gt;(T entity)
  {
      using (var transaction = Session.BeginTransaction())
      {
          if (entity is IEnumerable)
          {
              foreach (var item in (IEnumerable)entity)
              {
                  Session.Delete(item);
              }
          }
          else
          {
              Session.Delete(entity);
          }
  
          transaction.Commit();
      }
  }
  </code></pre>
  
  <p>As you can see, the only thing that differs is the <code>Session.[something]</code> part. How would I refactor this into only one method?</p>