我们正在使用动态链接构建搜索查询。有一个属性有一对多的关系。我们使用FirstOrDefaylt。但是当它要执行时会给出“没有适用的聚合方法'FirstOrDefault'存在的消息”。
这是我们写的查询:
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 : "";
执行点:
var _invoiceList = _tbBOSSWebEntities.Invoices.Where(quer)
.OrderBy(orderQuery);
这个查询错了吗?我该如何解决这个问题?