I have some errors that occur with this search function. I have two tables:
employees
and
attendance
. In table,
attendance
has
AddendanceDate(datetime)
column. I want to get the results absent lists of
employee
for today. For
datetime.today
, the result is good, but I want to choice the search keyword with other dates. How can I assign in this following code. When I assign
a.AttendanceDate== date
, I don't get the result.
My code is as follows:
public async Task<IEnumerable<AbsentReportsViewModel>> GetAllAbsentEmpAsync(DateTime date)
{
var query = await (from e in _dbContext.Employees
join attt in _dbContext.Attendances
on e.Id equals attt.EmployeeId into eGroup
from eattt in eGroup.Where
(a => a.AttendanceDate ==
DateTime.Today ).DefaultIfEmpty()
where eattt.AttendanceDate == null
select new AbsentReportsViewModel
{
JobId = e.JobId,
EmpReportName = e.NameMM,
DeptId = e.DeptId,
RankId = e.CurrentRankId,
DeptReportName = e.Department.DeptName,
RankReportName = e.Rank.RankName,
BarCode = e.Barcode,
EmpReportId = e.Id,
}).ToListAsync();
return query;
}
What I have tried:
public async Task<IEnumerable<AbsentReportsViewModel
>> GetAllAbsentEmpAsync(DateTime date)
{
var query = await (from e in _dbContext.Employees
join attt in _dbContext.Attendances
on e.Id equals attt.EmployeeId into eGroup
from eattt in eGroup.Where(a =>
a.AttendanceDate == date ).DefaultIfEmpty()
where eattt.AttendanceDate == null
select new AbsentReportsViewModel
{
JobId = e.JobId,
EmpReportName = e.NameMM,
DeptId = e.DeptId,
RankId = e.CurrentRankId,
DeptReportName = e.Department.DeptName,
RankReportName = e.Rank.RankName,
BarCode = e.Barcode,
EmpReportId = e.Id,
}).ToListAsync();
return query;
}