title: LINQ to SQL Calling stored procedure
body: <p>I have created small test web application which makes use of LINQ to SQL. I have ObjectDataSource and GridView. GridView's Datasource is ObjectDataSource. Now this ObjectDataSource uses one class(Method Name:GetAllTasks() as mentioned below) called MyTasks to populate all the task from Tasks table in SQL using Linq to SQL. It makes call to stored procedure GetAllMyTasks().</p>
  
  <p>I have following method which works perfectly. </p>
  
  <pre><code> public static IEnumerable&lt;GetAllMyTasksResult&gt; GetAllTasks()
  {
      MyTasksDataContext db = new MyTasksDataContext();
      var tasks = db.GetAllMyTasks().Select(x =&gt; x);
      return tasks;
  }
  </code></pre>
  
  <p>Now if i try to replace above code with following code just to make use of using key word to create Disposable MyTasksDataContext object. it gives me error saying "Invalid attempt to call Read when reader is closed.". Is there anything which i am missing here.</p>
  
  <pre><code> public static IEnumerable&lt;GetAllMyTasksResult&gt; GetAllTasks()
  {
      using (MyTasksDataContext db = new MyTasksDataContext())
      {
          var tasks = db.GetAllMyTasks().Select(x =&gt; x);
          return tasks;
      }
  }
  </code></pre>
  
  <p>Can anyone please give me reason behind this? I know that my MyTasksDataContext object is calling its dispose method.</p>