Hi,
I have an ASP.NET Core MVC app that contains two entities: Employee
and Task. The relationship between these two entities is One-to-many.
The information stored for an employee is the full name, email, phone
number, date of birth, and monthly salary. The task consists of a
title, description, assignee(the employee assigned to work on it), and a due date. I need to display the 5 employees who completed the largest number of tasks in the past month.
What I have tried:
public async Task<IActionResult> Display()
{
int current_month = DateTime.Now.Month;
var employees = _context.Employees.Include(t => t.EmployeeTasks).OrderByDescending(x => x.EmployeeTasks.Count(x => x.DueDate.Month == current_month - 1)).Take(5);
return View(employees);
}
This query is not working properly, as if it does not recognize the condition
DueDate.Month == current_month - 1
Does anyone know how to correct the given query?