title: Iterating values
body: <p>I'm new to linq. I'm using linq to <a href="https://stackoverflow.com/q/12496809/442580">fill some classes from the database</a>.</p>
  
  <p>All my objects are being filled correctly using my linq except for one small thing. Below you can see that for "SAR" "Flight Direction" (rows 15,16) I should have a value for <strong>Ascending</strong> and a value for <strong>Descending</strong>. But what <strong>I'm getting are two value objects for "Ascending"</strong>.</p>
  
  <p><strong>Why isn't it looping through my values? What is the LINQ missing?</strong></p>
  
  <h1>Here are my DB results:</h1>
  
  <p><img src="https://i.stack.imgur.com/QbGw4.png" alt="enter image description here"></p>
  
  <h1>Here is my LINQ:</h1>
  
  <pre class="lang-c# prettyprint-override"><code>using (NpgsqlDataReader reader = command.ExecuteReader())
  {
  
      if (reader.HasRows)
      {
  
          var groups = reader.Cast&lt;System.Data.Common.DbDataRecord&gt;()
              .GroupBy(dr =&gt; new { ID = (int)dr["id"], AttID = (int)dr["AttId"] })
              .GroupBy(g =&gt; g.Key.ID);
  
          typeDataList = (
              from typeGroup in groups
              let typeRow = typeGroup.First().First()
              select new TypeData()
              {
                  ID = (int) typeRow["id"],
                  Type = (string) typeRow["type"],
                  Attributes = 
                  (
                      from attGroup in typeGroup
                      let attRow = attGroup.First()
                      select new TypeDataAttribute()
                      {
                          ID = (int)attRow["AttId"],
                          Label = (string)attRow["label"],
                          PossibleValues =
                          (
                              from row in attGroup
                              where !DBNull.Value.Equals(attRow["AttValueId"])
                              select new TypeDataAttributeValue() { ID = (int)attRow["AttValueId"], Value = (string)attRow["value"] }
                          ).ToArray()
                      }
                  ).ToArray()
              }
          );
      }
  }
  </code></pre>