var invoice = (from i in Catalog.Invoices
where (i.Id == invoiceId)
select i)
.Include(i => i.Appointment.Service)
.Include(i => i.Appointment.Allocations.Select(a => a.Service))
.Include(i => i.Appointment.Allocations.Select(e => e.Employee))
.FirstOrDefault();
var inv = invoice.Appointment.Allocations.Select(e => e.Employee);
我的问题:如何过滤上述查询中的空值?
答案 0 :(得分:2)
您应该在查询中添加Where
子句,以过滤掉null
值。
在Select
之后:
var inv = invoice.Appointment.Allocations.Select(e => e.Employee).Where(e => e != null);
或Select
之前:
var inv = invoice.Appointment.Allocations.Where(e => e.Employee != null).Select(e => e.Employee);