title: Proper use of "Using" statement for datacontext
body: <p>I’m using Linq to Entities and lately, I found that a lot of folks recommending wrapping the datacontext in a using statement like this:</p>
  
  <pre><code>Using(DataContext db = new DataContext) {
      var xx = db.customers;
  }
  </code></pre>
  
  <p>This makes sense. However, I’m not sure how to incorporate this practice in my model.
  For example: I have an interface (let’s call it customer) and it is implemented by a repository like this:</p>
  
  <pre><code>namespace Models
  {
      public class rCustomer : iCustomer
      {
  
          readonly DataContext db = new DataContext();
  
          public customer getCustomer(Guid id)
          {
              return db.customers.SingleOrDefault(por =&gt; por.id == id);
          }
  
          public iQueryable&lt;customer&gt; getTopCustomers()
          {
              return db.customers.Take(10);
          }
  
          //*******************************************
          //more methods using db, including add, update, delete, etc.
          //*******************************************
  
      }
  }
  </code></pre>
  
  <p>Then, to take the advantage of using, I will need to change the methods to look like this:</p>
  
  <pre><code>namespace Models
  {
      public class rCustomer : iCustomer
      {
          public customer getCustomer(Guid id)
          {
              using(DataContext db = new DataContext()) {       
                  return db.customers.SingleOrDefault(por =&gt; por.id == id);
              } 
          }
  
          public iQueryable&lt;customer&gt; getTopCustomers()
          {
              using(DataContext db = new DataContext()) {       
                   return db.customers.Take(10);
              } 
          }
  
          //*******************************************
          //more methods using db
          //*******************************************
  
      }
  }
  </code></pre>
  
  <p>My question is: <strong>the recommendation of using “Using” is really that good?</strong> Please take in consideration that this change will be a major one, I have about 25 interfaces/repository combos, and each has about 20-25 methods, not to mention the need to re-test everything after finish.
  Is there other way?</p>
  
  <p>Thanks!</p>
  
  <p>Edgar.</p>