title: How to add SUM aggregate function into Entity Framework query
body: <p>I have a query:</p>
  
  <pre><code>var resultb = unitOfWork.deviceInstanceRepository.Get()
              .Select(s =&gt; new
              {
                  DeviceId = s.DeviceId,
                  Name = s.Device.Name,
                  Manufacturer = s.Device.Manufacturer1.Name,
                  Quantity = s.Quantity
              })
              .GroupBy(w =&gt; new
              {
                  w.DeviceId,
                  w.Name,
                  w.Manufacturer,
                  w.Quantity
              }).ToList();
  </code></pre>
  
  <p>I want to change this line:
  <code>Quantity= s.Quantity</code> </p>
  
  <p>into </p>
  
  <p><code>Quantity=Sum(s=&gt;s.Quantity)</code></p>
  
  <p>I found this <a href="http://msdn.microsoft.com/pl-pl/library/bb534734%28v=vs.110%29.aspx" rel="nofollow">Click</a>
  but still have some problems with implementing this. There is no Sum method in Intellisense.</p>
  
  <p>Ok when I change places of <code>Select</code> and <code>GroupBy</code> :</p>
  
  <pre><code>var resultb = unitOfWork.deviceInstanceRepository.Get()
              .GroupBy(w =&gt; new
              {
                  w.DeviceId,
                  w.Device.Name,
                  w.Device.Manufacturer,
                  w.Quantity
              })
              .Select(s =&gt; new
              {
                  DeviceId = s.DeviceId,
                  Name = s.Device.Name,
                  Manufacturer = s.Device.Manufacturer1.Name,
                  Quantity = s.Sum(s=&gt;s.Quantity)
              })
  </code></pre>
  
  <p>I can use <code>Sum</code> but then lines like : <code>s.DeviceId</code> throws error that <code>Anonymous type does not contain definition of deviceId</code>.
  Same error for <code>s.Device.Name</code> and <code>s&gt;device.Manufacuter1.Name</code></p>