title: Querying SQL Database using LINQ
body: <pre><code> SELECT Meter.SerialNumber as serial, 
   SupplyPoint.Id as supplypoint,
   SupplyType.Id as supplytype,
   SupplyType.Name as supplytypename
   FROM Meter
   INNER JOIN SupplyPoint ON Meter.SupplyPointId = SupplyPoint.Id
   INNER JOIN SupplyType ON SupplyPoint.SupplyTypeId = SupplyType.Id;
  </code></pre>
  
  <p>I have this query so that I might find the Supply Type of a meter based on it's serial. So far I've written this function:</p>
  
  <pre><code>var query = from meters in db.Meters
  join supplyPoint in db.SupplyPoints on meters.SupplyPointId
  equals supplyPoint.Id
  join supplyType in db.SupplyTypes on supplyPoint.SupplyTypeId equals             
  supplyType.Id
  select new { serial = meters.SerialNumber, type = supplyType.Name };
  foreach (var meter in query)
      {
          if (meter.serial == serial)
              return meter.type;
      }
  return "Meter Type Not Specified";`
  </code></pre>
  
  <p>So I call FindType(string serial) and it returns the type. Can anyone suggest better code for converting such a query? Any directions on where to learn more about LINQ are welcome too.</p>