Q: No applicable aggregate method 'FirstOrDefault' exists 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".
This is the query we have written:
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 > 0 ? " and Sale.SaleNumber=\"" + saleNo + "\"" : " Sale.SaleNumber=\"" + saleNo + "\"" : "";
quer += lotNumber != "" ? quer.Length > 0 ? " and InvoiceSales.FirstOrDefault().LotNo=\"" + lotNumber + "\"" : "InvoiceSales.FirstOrDefault().LotNo=\"" + lotNumber + "\"" : "";
quer += markID != "" ? quer.Length > 0 ? " and EstateID=" + markID : "EstateID=" + markID : "";

execution point:
var _invoiceList = _tbBOSSWebEntities.Invoices.Where(quer)
            .OrderBy(orderQuery);

Is this query wrong? How can I solve this?
