title: Nested Linq performance
body: <p>We have 2 tables (tblSerials and tblRequests). The question is how can we make this code to execute faster? As you can see "from request in ctx.tblRequests" parts are very similar. Any other better solution?</p>
  
  <pre><code>var list = from s in ctx.tblSerials
          orderby s.CreateDate descending
          select new
          {
           SerialGUID = s.SerialGUID,
           CreateDate = s.CreateDate,
           NumberOfAllRequests = 
              (from request in ctx.tblRequests
                where request.SerialGUID.ToLower().Equals(s.SerialGUID.ToLower())
                select request.RequestGUID).Count(),
           NumberOfAllRequestsDistinctByMachine = 
              (from request in ctx.tblRequests
                where request.SerialGUID.ToLower().Equals(s.SerialGUID.ToLower())
                select request.MachineCode).Distinct().Count(),                    
          };
  </code></pre>