title: ASP.NET MVC guidelines for static classes for database access
body: <p>The way I am utilising the MVC pattern at the moment in my ASP.NET application (using Entity Framework) is as follows:</p>
  
  <p>1) My <code>Models</code> folder contains all EF entities, as well as my ViewModels</p>
  
  <p>2) I have a <code>Helpers</code> folders where I store classes created for the purposes of the particular application.</p>
  
  <p>3) In my <code>Helpers</code> folder, I have a static class named <code>MyHelper</code> which contains methods that access the DB using EF.</p>
  
  <pre><code>namespace myApp.Helpers
  {
      public static class MyHelper
      {
          public static async Task&lt;ProductVM&gt; GetProductAsync(int productId)
          {
              using (var context = new myEntities())
              {
                  return await context.vwxProducts.Where(x =&gt; x.ProductId == productId).Select(x =&gt; new ProductVM { A = x.A, B = x.B }).FirstOrDefaultAsync();
              }
          }
      }
  }
  </code></pre>
  
  <p>4) My controllers then call these functions where necessary:</p>
  
  <pre><code>namespace myApp.Controllers
  {
      public class ProductController : Controller
      {
  
          [HttpGet]
          public async Task&lt;ActionResult&gt; Index(int productId)
          {
              var productVM = await MyHelper.GetProductAsync(productId);
              return View(productVM);
          }
      }
  }
  </code></pre>
  
  <p>I usually encounter comments in SO of the type "don't use a static class, static classes are evil, etc". Would this apply in such a scenario? If yes, why? Is there a better 'structure' my app should follow for best practices and for avoiding such pitfalls?</p>