Just wondering, is this the most efficient way to do this? is there a way to have all linq inside the same statement instead of calling a method like a subheading or something else?
newEmployee = (from emp in db.employees select new { a.EmployeeID, a.Username, Status = emp.GetEmployeeCurrentStatus(a.Username) }).ToList();
This is GetEmployeeCurrentStatus, which returns the employee status:
public string GetEmployeeCurrentStatus(string username) { using (Entities db = new Entities()) { var times = (from d in db.TimeTables where d.DateTime == DateTime.Today && d.Employee.Username == username select d) .OrderByDescending(d => d.TimeID).FirstOrDefault(); return (x.ClockOut == null ? "IN" : "OUT"); } }
source share