Can some kind soul please lend me the Linq To SQL query for the following T-SQL Query
SELECT e.EmployeeName, MIN(a.SignInTime), MAX(a.SignOutTime)
FROM Employee e
LEFT OUTER JOIN Attendance a ON e.Id = a.EmployeeId AND CAST (CONVERT (varchar, a.SignInTime, 106) AS DATETIME) = '28 APR 2009'
GROUP BY e.EmployeeName
The database schema i have is as follows
Employee: {Id: int identity PK, EmployeeName: varchar(200) NOT NULL}
Attendance: {Id: int identity PK, EmployeeId: int FK(Employee(Id)) NOT NULL, SignInTime: DateTime, SignOutTime: DateTime}
NOTE: The Convert gimmick is only used to chop off the time portion in the SignInTime for comparision
This is definitely a challenge. It’s ugly, but It does the trick. It returns exactly what you are looking for. In the case of employees without attendance, you get back the name with null times.
This is the SQL that is emitted by that expression:
This is very close to your original SQL. I added where “t.SignInTime == null” so that it returns employees with attendance, but you can remove that if that’s not what you want.