title: Declaring Entity FrameWork Contexts with using
body: <p>Which is the Best Practise in Declaring Entity FrameWork Contexts</p>
  
  <pre><code>function()
  {
      DBContext context = new DBContext();
  
      //Entity code
  
      return ;
  }
  </code></pre>
  
  <p>or</p>
  
  <pre><code>function()
  {
      using(DBContext context = new DBContext())
      {
          //Entity code
      }
  }
  </code></pre>
  
  <p>Do we need to use using in EntityFrameWork ? If yes my 2nd question</p>
  
  <p>In DataAccess Layer am executing EF and storing the result in IEnumerable inside using</p>
  
  <p>MY DL</p>
  
  <pre><code>function()
  {
      IEnumerable something = null;
      using(DBContext context = new DBContext())
      {
          IEnumerable something = ....
      }
      return something;
  }
  </code></pre>
  
  <p>In Controller</p>
  
  <pre><code>function()
  {
      List some = something.ToList();
  }
  </code></pre>
  
  <p>And in my controller am getting this as a list as i need to do some Find operation am getting</p>
  
  <pre><code>"The operation cannot be completed because the DbContext has been disposed Entity Framework"
  </code></pre>
  
  <p>Yes i can return a list from DL and it works fine</p>
  
  <p>How do i handle this if i use using with IEnumerable? </p>