title: What is an efficient/quick way to populate a C# struct with SQL table info?
body: <p>In a nutshell:  I have some database table data that I want to populate c# structs with.</p>
  
  <p>For example:</p>
  
  <pre><code>struct Phone
  {
      public int PhoneID;
      public string Number;
  }
  struct Patient
  {
      public Phone WorkPhone;
  }
  </code></pre>
  
  <p>And the SQL tables look like this:  </p>
  
  <pre><code>Patient table:  
      Patient ID, Patient Name, etc.  
  Phone table:  
      PhoneID, Number, Phone Type etc.  
  </code></pre>
  
  <p>Basically the structs are mirrors of the SQL tables.  </p>
  
  <p>I have the primary key (<code>PhoneID</code>), that I am passing through a select statement.  So I will only retrieve one row in the case of the patient or up to 5 rows for the Phone table (They can have <code>Work</code>, <code>Cell</code>, <code>Home</code>, etc). </p>
  
  <p>I don't have a great way to stuff this table into a struct easily.  What I am doing now is one by one.  You can see for hundreds of variables per patient, it's a very tedious and highly code intensive process.  Is there some way, maybe I can have a variable in the variable name, for example if the column name is Phone then it would stuff the Phone variable.  Hope that makes sense.</p>
  
  <pre><code>query = "SELECT * FROM Phone p WHERE p.StatusID = 'A' AND ObjectTypeID = 'PA' AND ObjectID = '" + PatientID.ToString() + "'";
  SqlDataAdapter a1 = new SqlDataAdapter(query, dataConnection);
  DataTable t1 = new DataTable();
  a1.Fill(t1);
  DataTableReader r1 = t.CreateDataReader();
  //object value = null;
  while (reader.Read())
  {
      for (int i = 0; i &lt; r1.FieldCount; i++)
      {
          if (!r1.IsDBNull(i))
          {
              if reader.GetValue(i)
              switch (r1.GetName(i))
              {
                  case "PhoneID": { pr.HomePhone.PhoneID = (int)reader.GetValue(i); break; }
                  case "PhoneTypeID": { pr.HomePhone.PhoneTypeID = (string)reader.GetValue(i); break; }
                  case "ObjectID": { pr.HomePhone.ObjectID = (int)reader.GetValue(i); break; }
                  case "ObjectTypeID": { pr.HomePhone.ObjectTypeID = (string)reader.GetValue(i); break; }
  </code></pre>