title: Return List of Objects from stored procedure return data C#
body: <p>I have a method that is calling a stored procedure and returning a list of objects. I am not sure how to add the result from the stored procedure to the list of objects. I tried to use model. Add but anyway I am using it I am getting error. I have identify the place I need help inside the code.</p>
  
  <p>This is my code:</p>
  
  <pre><code>    public List&lt;Models.Type&gt; get_Type(string Type_Group)
      {
          string connectionName = getConnectionStr();
          List&lt;Models.Type&gt; model = null;
  
          string myConnection = System.Configuration.ConfigurationManager.ConnectionStrings[connectionName].ToString();
          SqlDatabase db = new SqlDatabase(myConnection);
  
          using (DbCommand command = db.GetStoredProcCommand("LA_Get_Type"))
          {
              db.AddInParameter(command, "Type_Group", DbType.String, Type_Group);
  
              var result = db.ExecuteReader(command);
  
              try
              {
                  if (result.FieldCount == 0)
                      model = null;
                  else
                  {
                      while (result.Read())
                      {
                       model = new List&lt;Models.Type&gt;()
                          {
  
      //This is the place I don't know I tried   model.Add but not sure what 
       to have after. 
       This code is when I have returning just 1 object but I want to 
       return list of objects                           
  
  
                              typeID = Convert.ToInt32(result["typeID"].ToString()),
                              type_group = result["type_group"].ToString(),
                              type_value = result["type_value"].ToString(),
                              type_desc = result["type_desc"].ToString(),
                              type_sort = Convert.ToInt32(result["type_sort"].ToString())
                          };
                      }
                  }
              }
              catch (Exception ex)
              {
              }
              result.Close();
              return model;
          }
      }
  </code></pre>
  
  <p>and this is my object:</p>
  
  <pre><code>  public class Type
    {
  
      public int typeID { get; set; }
      public string type_group { get; set; }
      public string type_value { get; set; }
      public string type_desc { get; set; }
      public int type_sort { get; set; }
  
    }
  </code></pre>