JasinCole
Well-known member
- Joined
- Feb 16, 2023
- Messages
- 66
- Programming Experience
- 1-3
I am trying to get the following code to work, but I do not believe I fully understand how this relationship fixup works. I want GetEmployeeRecordWithFilteredPayrecs() to return an employee with only the payrecs that belong to a certain payperiod.
I am sure this more of a "I do not understand" so a general explanation of the right approach and what needs to happen would probably benefit me most.
I am sure this more of a "I do not understand" so a general explanation of the right approach and what needs to happen would probably benefit me most.
C#:
var payPeriods = new List<DateTime>
{
DateTime.Parse("11/6/2022"),
DateTime.Parse("11/13/2022"),
DateTime.Parse("11/20/2022"),
DateTime.Parse("11/27/2022")
};
var employeeNum = 1006;
var employee = srvc.GetEmployeeRecordWithFilteredPayrecs(employeeNum,
payrec => payrec.Empnum == employeeNum && payPeriods.Contains((DateTime)payrec.Payprd!));
C#:
public Employ? GetEmployeeRecordWithFilteredPayrecs(int employeeNum, Func<Payrec, bool> expression)
{
var employee = EmployeeRecordById(employeeNum);
if (employee != default)
{
var _ = _ctx.Payrecs
.Where(expression);
}
return employee;
}
private Employ? EmployeeRecordById(int employeeNum)
{
return _ctx.Employs
.FirstOrDefault(employee => employee.Recnum == employeeNum);
}