title: Linq two select statements, second one uses first ones result,
body: <p>This linq query works well.      </p>
  
  <pre><code>var qry = context.Boxes
            .GroupBy(k=&gt;k.Box_ID)
            .Select( group =&gt; new {
                Box_ID = group.Key,
                TotalA = group.Sum(p =&gt; p.A),
                TotalC = group.Sum(p =&gt; p.C)
            })
            .Select(p =&gt; new {
                Box_ID = p.Kasa_ID,
                TotalA = p.TotalA,
                TotalC = p.TotalC,
                DiffAC = p.TotalA - p.TotalC
            });
  </code></pre>
  
  <p>But, i saw these type select statements, second one uses first select's anonymous type result, written like this: </p>
  
  <pre><code>  var qry = context.Boxes
              .GroupBy(k =&gt; k.Box_ID)
              .Select(group =&gt; new
              {
                  Box_ID = group.Key,
                  TotalA = group.Sum(p =&gt; p.A),
                  TotalC = group.Sum(p =&gt; p.C)
              })
              .Select(p =&gt; new
              {
                  Box_ID,  //*** compiler error
                  TotalA,  //I'm asking about these 3 lines, is this syntax possible 
                  TotalC,  //TotalC = p.TotalC,
                  DiffAC = p.TotalA - p.TotalC // calculate
              });
  </code></pre>
  
  <p>comments contains details. </p>
  
  <p>When i try to compile second query, compiler gives me the error "The name 'Box_ID' does not exist in the current contex".</p>
  
  <p>In fact there is no doubt with first syntax, but second one is more readable. How can i use second syntax? or in which condititons i can use it.</p>