我在下面的工资单程序中有以下代码。第一个字典包含主数据表中保存的员工 ID 和相应的基本工资。第二个字典保存员工 ID 和相应的基本工资,保存在薪金装配表中 - 用于处理。我想更新主表中不匹配的每个员工 ID 的基本工资。(工资变化)。
var OHEMDictionary = employees.OrderBy(es => es.empID)
.ToDictionary(od => od.empID,
od => od.salary);
var SalaryFitmentDictionary = salaryFitments
.Where(x => x.U_PD_Code.Trim().ToString() == "SYS001")
.OrderBy(es => es.U_Employee_ID)
.ToDictionary(od => od.U_Employee_ID,
od => od.U_PD_Amount);
var difference = OHEMDictionary
.Where(kv => SalaryFitmentDictionary[kv.Key] != kv.Value);
difference.ToList().ForEach(x =>
{
decimal salary = x.Value.Value;
var codeToUpdate = salaryFitments
.Where(y => y.U_Employee_ID.Equals(x.Key))
.Select(z => z.Code)
.SingleOrDefault(); `**<---exception thrown here**`
var salaryFitment = salaryFitmentService
.GetSalaryFitment(codeToUpdate);
if (salaryFitment != null)
{
// Save record
salaryFitmentService
.UpdateSalaryFitment(salaryFitment, salary.ToString());
}
});
但是,我不断收到错误消息'Sequence contains more than one element'
。我该如何解决这个错误?