2014-03-13 122 views
0
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); 

enter image description here過濾空值

我的問題:如何將空值從上面的查詢過濾器?

回答

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); 
+0

由於它的工作。 :) – Sampath