这是我的Attendance
课程
public class EmployeeAttendance
{
public string Employee { get; set; }
public DateTime Date { get; set; }
public string EmployeeClockTimeId { get; set; }
}
逻辑
List<EmployeeAttendance> attendancesPerDay = new List<EmployeeAttendance>();
List<EmployeeAttendance> employeeAttendances = new List<EmployeeAttendance>();
foreach (var attendance in employeeAttendances)
{
if (attendancesPerDay.Contains(attendance))
{
continue;
}
attendancesPerDay = employeeAttendances.Where(x => x.Date == DateTime.Now.Date && x.EmployeeClockTimeId == 12.ToString()).ToList();
Validation(attendancesPerDay);
}
我将有employeeAttendances
。这包含所有员工出勤日期明智。这将是一个很大的名单。我需要将每组记录发送到验证方法和empid。我是通过上面的代码实现的。但它花了很多时间。有没有更好的方法来跳过所有的AttendancesPerDay
记录,而不是像循环中一个一个地去。
注意:在一天内会有多个条目,比如每次emp出去并进来。比方说20条记录。我希望所有20条记录都能将其发送给验证。并且下一次迭代必须是21条记录。但现在我只是继续这一点
你可以在linq中使用qazxsw poi方法并为你的IEnumerable<TSource>.Except
类实现qazxsw poi。
IEqualityComparer<EmployeeAttendance>
并将你的逻辑改为此
EmployeeAttendance
我想的可能太多了。这就是为什么我错过了这个简单的事情。我最终这样使用了
public class EmployeeAttendanceEqualityComparer : IEqualityComparer<EmployeeAttendance>
{
public bool Equals(EmployeeAttendance x, EmployeeAttendance y)
{
if (x == null || y == null)
return false;
// check your equality same as this
return x.Employee == y.Employee;
}
public int GetHashCode(EmployeeAttendance obj)
{
// or something else
return 12;
}
}