title: How to implement one to many relationship
body: <p>I have a one to many relationship coming from a stored procedure. I have several one to many relationships in the query and i am trying to map these fields to a C# object. The problem i am having is i get duplicate data because of the one to many relationships. Here is a simplified version of my code:</p>
  
  <p>Here is the objects classes:</p>
  
  <pre><code>public class Person
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public List&lt;Color&gt; FavoriteColors { get; set; }
      public List&lt;Hobby&gt; Hobbies { get; set; }
  
      public Person()
      {
          FavoriteColors = new List&lt;Color&gt;();
          Hobbies = new List&lt;Hobby&gt;();
      }
  }
  
  public class Color
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  
  public class Hobby
  {
      public int Id { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>Here is how I am retrieving the data:</p>
  
  <pre><code>using (SqlConnection conn = new SqlConnection("connstring.."))
  {
      string sql = @"
                      SELECT 
                          Person.Id AS PersonId, 
                          Person.Name AS PersonName, 
                          Hobby.Id AS HobbyId,
                          Hobby.Name AS HobbyName,
                          Color.Id AS ColorId,
                          Color.Name AS ColorName
                      FROM Person
                      INNER JOIN Color on Person.Id = Color.PersonId
                      INNER JOIN Hobby on Person.Id = Hobby.PersonId";
      using (SqlCommand comm = new SqlCommand(sql, conn))
      {
          using (SqlDataReader reader = comm.ExecuteReader(CommandBehavior.CloseConnection))
          {
              List&lt;Person&gt; persons = new List&lt;Person&gt;();
              while (reader.Read())
              {
                  Person person = new Person();
                  //What to do
              }
          }
      }
  }
  </code></pre>
  
  <p>As you can see there can be multiple colors and hobbies for a given Person. Usually, I would use Entity Framework to solve this mapping but we are not allowed to use any orms. Is there a technique to properly unflatten this data?</p>