title: How do I return a table from a SQL query as a List in C#?
body: <p>I have a Xamarin app that connects to a SQL Server (*), and I want to insert the data from the SQL Server's tables into a local SQLite database. My approach is to execute a query like </p>
  
  <pre><code>select * from Table1
  </code></pre>
  
  <p>retrieve the results of the query as a <code>List</code>, then insert that <code>List</code> into my SQLite table. That said I'm very new at using <code>SqlClient</code>, so please share if there are better ways to do this. Thanks.</p>
  
  <p>Edit: the smallest number of columns these tables have is 5. Don't know if that disqualifies Lists as the best option.</p>
  
  <p>My code:</p>
  
  <pre><code>private void LoadData()
  {
      string cs = @"connection string here";
  
      using (SqlConnection sconn = new SqlConnection(cs))
      {
          sconn.Open();
  
          SqlDataReader reader = null;
  
          SqlCommand aml = new SqlCommand("select * from Table1");
          reader = aml.ExecuteReader();
  
          while (reader.Read())
          {
              // get result of query as List somehow?
          }
  
          using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
          {
              conn.CreateTable&lt;Table1&gt;();
  
              if (conn.Query&lt;Table1&gt;("select * from Table1").Count() &lt;= 0)
              {
                  // insert the list object
              }
          }
      }
  }
  </code></pre>
  
  <p>(*) The app does not use a web service as the app is intended for onsite use only and will not be distributed publicly.</p>