title: Generic data access code to stored procedures to return Enumerable<t>?
body: <p>Instead of repeating the same ADO.net code with a different Enumerable, I want to make it more generic and reusable.</p>
  
  <p>I have the following ADO.Net code to return a collection of objects:</p>
  
  <pre><code>public static IEnumerable&lt;TasCriteria&gt; GetTasCriterias()
      {
          using (var conn = new SqlConnection(_connectionString))
          {
              var com = new SqlCommand();
              com.Connection = conn;
              com.CommandType = CommandType.StoredProcedure;
  
              com.CommandText = "IVOOARINVENTORY_GET_TASCRITERIA";
              var adapt = new SqlDataAdapter();
              adapt.SelectCommand = com;
              var dataset = new DataSet();
              adapt.Fill(dataset);
  
              var types = (from c in dataset.Tables[0].AsEnumerable()
                           select new TasCriteria()
                           {
                                TasCriteriaId = Convert.ToInt32(c["TasCriteriaId"]),
                                TasCriteriaDesc= c["CriteriaDesc"].ToString()
                           }).ToList&lt;TasCriteria&gt;();
  
              return types;
          }
  
      }
  </code></pre>
  
  <p>Model:</p>
  
  <pre><code> public class TasCriteria
      {
          public int TasCriteriaId { get; set; }
          public string TasCriteriaDesc { get; set; }
      }
  </code></pre>