title: linq2sql: singleton or using, best practices
body: <p>what is the preferred practice when linq2sql using (in asp.net mvc applications): to create "singleton" for <code>DataContext</code> like:</p>
  
  <pre><code>partial class db
  {
      static db _db = new db(global::data.Properties.Settings.Default.nanocrmConnectionString, new AttributeMappingSource());
  
      public static db GetInstance()
      {
          return _db;
      }
  }
  </code></pre>
  
  <p>or to retrieve new instance when it needed within <code>using</code>:</p>
  
  <pre><code>using (db _db = new db())
  {
      ...
  }
  </code></pre>
  
  <p>the usage of <code>using</code> brings some limitations into code. so I prefer to use singleton one. is it weird practice?</p>
  
  <p><strong>UPD</strong>:<br>
  explanation why i'm using singleton:</p>
  
  <pre><code>public class UserGroupRepository
  {
      public static IQueryable&lt;Group&gt; RolesFor(string username)
      {
          User user = UserRepository.WithUsername(username);
  
          return from g in db.GetInstance().Groups
                  join ug in db.GetInstance().UsersGroups on g.Id equals ug.GroupId
                  where ug.UserId == user.Id
                  select g;
      }
  }
  </code></pre>
  
  <p>i have this method. due to it returns IQueryable - I can continue composing query without it executing, so here just lazy result returns.<br>
  if i rewrite the same code with <code>using</code> - i cannot be able to return IQueryable (because db will be disposed and IQueryable will be lost too), and i would change it to List. and now this method will return "huge" List from which i will filter data on previous function.</p>
  
  <p>i hope i describe enough detailed.</p>