我有一个查询,我试图将Staff
表连接到新表JobInfo
,
在staff.StaffID
到jobinfo.staff_id
上。
var leaveSearchResult =
(from staff in db.Staffs
join leave in db.LeaveApplication
on staff.StaffID equals leave.StaffID
join appliedLeave in db.AppliedLeaves
on leave.LeaveApplicationID equals appliedLeave.LeaveApplicationID
join staffLeave in db.StaffLeaves
on leave.StaffID equals staffLeave.StaffID
join leaveType in db.LeaveTypes
on staffLeave.LeaveID equals leaveType.LeaveTypeID
where leave.LeaveStatus == LeaveBusinessLogic.AppliedLeaveStatus.Approved.ToString()
//join JobInfo table based on staffid
join jobinfo in db.JobInfo
on staff.StaffID equals jobinfo.staff_id
select new { staffDetails = staff, leaveDetails = leave, appliedLeaves = appliedLeave }).Distinct().AsQueryable();
在JobInfo
表中,每个staff_id
的记录可能不止一个
如何基于staff_id
表中的最高主键jobinfo_id
为每个JobInfo
检索1条记录?
例如
join jobinfo in db.JobInfo
on staff.StaffID equals (jobinfo.staff_id).OrderByDescending(jobinfo.jobinfo_id).Distinct()
//^currently showing error