Sampath
Sampath

Reputation: 65870

Filter null values of the entity framework query

 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

My Question : How to filter the null values from above query ?

Upvotes: 0

Views: 1867

Answers (1)

khellang
khellang

Reputation: 18102

You should add a Where clause to the query to filter out the null values.

Either after the Select:

var inv = invoice.Appointment.Allocations.Select(e => e.Employee).Where(e => e != null);

or before the Select:

var inv = invoice.Appointment.Allocations.Where(e => e.Employee != null).Select(e => e.Employee);

Upvotes: 2

Related Questions