我有这个linqued查询
var moreThen1dayLeavefed = (from LApp in db.LeaveApplications
join Emp in db.Employees
on LApp.Employee equals Convert.ToInt32(Emp.EmployeeNumber)
join LBrk in db.LeaveBreakups
on LApp.Id equals LBrk.LeaveApplication
where Emp.Team == 8 && LBrk.StartDate.Year == 2015 && LBrk.StartDate.Month == 5
select new { StartDate = LBrk.StartDate.Day, EndDate = LBrk.EndDate.Day, diff = (DbFunctions.DiffDays(LBrk.StartDate, LBrk.EndDate) + 1) }).ToList();
它会出错LINQ to Entities无法识别方法"Int32 ToInt32(System.String)"方法,并且此方法无法转换为存储表达式。在3号线上,即
on LApp.Employee equals Convert.ToInt32(Emp.EmployeeNumber)
当我在内部联接期间将字符串转换为int时
刚刚看到您的相关问题。您的EmployeeNumber
字段似乎填充了固定大小(5)的数字的左零填充字符串表示。如果这是真的,您可以使用从如何用linq-lambdas对包含数值的varchar列进行排序到Entity的技巧来解决这个问题。
只需更换
on LApp.Employee equals Convert.ToInt32(Emp.EmployeeNumber)
带有
on DbFunctions.Right("0000" + LApp.Employee.ToString(), 5) equals Emp.EmployeeNumber