C
C#3w ago
WAASUL

Data retrieval EF-core

private static readonly Expression<Func<Shift, ShiftDTO>> MapShiftToDto = shift => new ShiftDTO
{
Id = shift.Id,
Date = shift.Date,
Start = shift.Start,
End = shift.End,
Break = shift.Break,
Overtime = shift.Overtime,
DepartmentId = shift.DepartmentId,
Department = new DepartmentDTO
{
Id = shift.DepartmentId,
Name = shift.Department.Name,
Color = shift.Department.Color,
}
};
private static readonly Expression<Func<Shift, ShiftDTO>> MapShiftToDto = shift => new ShiftDTO
{
Id = shift.Id,
Date = shift.Date,
Start = shift.Start,
End = shift.End,
Break = shift.Break,
Overtime = shift.Overtime,
DepartmentId = shift.DepartmentId,
Department = new DepartmentDTO
{
Id = shift.DepartmentId,
Name = shift.Department.Name,
Color = shift.Department.Color,
}
};
I have a question regarding this. The department info is quite important on the client side. I do have a query that fetches the departments. I could for instance just get the department on the client side. The problem is that it makes the process very complicated. Also what if the departments on the client side are dirty meaning outdated or another user just created another department on some other device. All of a sudden the department will not be available. Should i also return the department when returning the shifts?
2 Replies
Angius
Angius3w ago
If a shift has a department, and you need both... fetch them both So I'd say your query here is just fine
WAASUL
WAASULOP3w ago
That would definitely simplify.
Want results from more Discord servers?
Add your server