处理相关实体的Null值

时间:2019-01-27 07:36:34

标签: linq

如果从相关实体中找不到匹配结果,我想设置默认值。

我试图显示来自第一个实体的所有值,但显示来自第二个表的两个值,第二个表中的任何一个值或两个值都可以为null。这是我的查询

var employeelist = _context.TblEmployee.ToList();

    foreach (var employee in employeelist)
    {               
        var employeeAtt = _context.AttendanceTable

            .GroupBy(a => a.DateAndTime.Date)
                .Select(g => new EmployeeAtt
                {
                    Date = g.Key,
                    Emp_name = employee.EmployeeName,
                    InTime = g.Where(e => e.ScanType == "I").Min(e => e.DateAndTime.TimeOfDay),
                    OutTime = g.Where(e => e.ScanType == "O").Max(e => e.DateAndTime.TimeOfDay),

                });
        empWithDate.AddRange(employeeAtt);
    }

如果值是NULL,我希望InTime和OutTime存储“缺席”。

enter image description here

enter image description here

0 个答案:

没有答案