int InvoiceAmount = 1000000; var results = from cl in Context.clients.ToList().Distinct() from inv in cl.invoices.ToList().Where(x => x.invoiceamount >= InvoiceAmount) where cl.id == inv.clientid select cl;clients and invoices are the two underlying tables and are joined on id->clientid fields, where one client has one or more invoices, in my attempt shown above I thought I would only get invoices ( invoices is a navigational property of client ) with a value >= InvoiceAmount but I get all that are linked to a client. I think it must be down to LINQ's deferred execution but don't know how to work around it except by filtering the invoice list again which is not ideal
int i = 0; foreach (client c in results) { i++; Console.WriteLine("Company: {0} (id: {1})", c.companyname, c.id); foreach (invoice inv in c.invoices) // This is where I think the query selects all invoices related to the current client. { Console.WriteLine("\t Invoice reference: {0}", inv.invoicereference); Console.WriteLine("\t\t Invoice date: {0}", inv.invoicedate.Value.ToString("dd/MM/yyyy")); Console.WriteLine("\t\t Invoice amount: {0}", inv.invoiceamount.Value.ToString("C")); Console.WriteLine("\t\t Charge type: {0}", inv.chargetypes.chargetypename); }