title: No applicable aggregate method 'FirstOrDefault' exists
body: <p>We are building search query using dynamic link . There one property has one to many relationship. There for we use FirstOrDefaylt. But when it going to execute it gives message of "No applicable aggregate method 'FirstOrDefault' exists".</p>
  
  <p>This is the query we have written:</p>
  
  <pre><code>var saleYear = dictionary["saleYear"] != null ? dictionary["saleYear"].ToString() : "";
  var saleNo = dictionary["saleNo"] != null ? dictionary["saleNo"].ToString() : "";
  var lotNumber = dictionary["lotNumber"] != null ? dictionary["lotNumber"].ToString() : "";
  var markID = dictionary["markID"].ToString() != "0" ? dictionary["markID"].ToString() : "";                
  
  quer += saleYear != "" ? "Sale.SaleYear=\"" + saleYear + "\"" : "";
  quer += saleNo != "" ? quer.Length &gt; 0 ? " and Sale.SaleNumber=\"" + saleNo + "\"" : " Sale.SaleNumber=\"" + saleNo + "\"" : "";
  quer += lotNumber != "" ? quer.Length &gt; 0 ? " and InvoiceSales.FirstOrDefault().LotNo=\"" + lotNumber + "\"" : "InvoiceSales.FirstOrDefault().LotNo=\"" + lotNumber + "\"" : "";
  quer += markID != "" ? quer.Length &gt; 0 ? " and EstateID=" + markID : "EstateID=" + markID : "";
  </code></pre>
  
  <p>execution point:</p>
  
  <pre><code>var _invoiceList = _tbBOSSWebEntities.Invoices.Where(quer)
              .OrderBy(orderQuery);
  </code></pre>
  
  <p>Is this query wrong? How can I solve this?</p>