title: Passing an anonymous type as T
body: <p>In the Entity Framework you can run and bind custom queries on-the-fly like so...</p>
  
  <pre><code>protected class NitrogenMoisutreContainer
  {
      public double MinN { get; set; }
      public double MaxN { get; set; }
      public double MinM { get; set; }
      public double MaxM { get; set; }
  }
  
  // ...
  
  var q = dbcontext.Database.SqlQuery&lt;NitrogenMoisutreContainer&gt;(@"SELECT MAX(NitrogenBalance) as MaxN, MIN(NitrogenBalance) as MinN, MAX(FCWaterPercent) as MaxM, MIN(FCWaterPercent) as MinM
                                                                      FROM agZoneProjectionGrowthStages
                                                                      WHERE NitrogenBalance &gt; 0 AND FCWaterPercent &gt; 0").First();
  </code></pre>
  
  <p>The problem is that, to me, this feels messy. I had to create this class for one query and <strong>I will never use it again for anything else</strong>. The results are used exactly one line down from where it is executed.</p>
  
  <p>Is there a way I can return an anonymous type? Even if I had to declare it first, like this...</p>
  
  <pre><code>var anonItem = new {
      MinN = 0d,
      MaxN = 0d,
      MinM = 0d,
      MaxM = 0d
  };
  
  var q = dbcontext.Database.SqlQuery&lt;anonItem.GetType()&gt;("...");
  </code></pre>
  
  <p>I just can't figure out how to pass in my anonymous type's <code>Type</code> as <code>T</code>. Is it possible?</p>