问题描述
documentNumber为string类型:数据为:201509001201509002201509003201511001201511002201511003201511004.....如何查询201509003-201511002之间的记录。我的想法是通过转为数值来处理,做法如下:varresult=(fromaindb_OA.VehicleMaintenanceRecordsjoinbindb_OA.VehicleDatasona.licensePlateequalsb.licensePlatejoincindb_OA.PayoffTablesona.documentNumberequalsc.documentNumberintoGrpfromgrpinGrp.DefaultIfEmpty()where(grp.receiptDate==null||a.leaveFactoryDate==null)orderbya.documentNumberdescendingselectnew{documentNumber=int.Parse(a.documentNumber),//单号为:string类型licensePlate=b.licensePlate,//车牌号vehicleOwner=b.vehicleOwner,//车主registrationDate=a.registrationDate,//登记(进厂)日期twoLevelMaintenance=a.twoLevelMaintenance,//二保maintenanceProject=a.maintenanceProject,//检查项目materialCost=db_OA.OutRecordTBs.Where(n=>n.documentNumber==a.documentNumber).Sum(n=>n.sellingPrice.HasValue?n.sellingPrice*n.outNumber:0),//配件金额settlementMark=db_OA.PayoffTables.Any(n=>n.documentNumber==a.documentNumber),//结算manHourCost=db_OA.PayoffTables.FirstOrDefault(n=>n.documentNumber==a.documentNumber).manHourCost,//工时费leaveFactoryDate=a.leaveFactoryDate,//出厂日期collectionAmount=grp.collectionAmount//收款金额}).ToList();varorderList=result.Where(p=>p.documentNumber>=s_documentNumber&&p.documentNumber>=e_documentNumber);错误提示为:LINQtoEntitiesdoesnotrecognizethemethod'Int32Parse(System.String)'method,andthismethodcannotbetranslatedintoastoreexpression.请高人指点。谢谢我的QQ:191971159
解决方案
解决方案二:
先Tolist再select
解决方案三:
documentNumber=int.Parse(a.documentNumber),//单号为:string类型应该是你强行把int型付给了string型导致,你可以在最后的Where条件里,才进行int转换,这里原样赋值就行
解决方案四:
documentNumber=int.Parse(a.documentNumber)改成documentNumber=Convert.ToInt32(a.documentNumber)试试
解决方案五:
a.documentNumber出现了非数字的字符了呗