Q: EF Core include an ICollection with a filter on the collection's referenced object I need a query that will return all Drivers including the Departures collection for each, where each collection is filtered by properties of the Departure.
This query:
// id supplied by HTTP POST
var driver = await _context.Drivers
  .Include(d => d.Departures.Where(dd => dd.Acknowledged == false))
  .SingleOrDefaultAsync(m => m.ID == id);

Generates an error:

InvalidOperationException: The property expression 'd => {from
  Departure dd in d.Departures where ([dd].Acknowledged == False) select
  [dd]}' is not valid. The expression should represent a property
  access: 't => t.MyProperty'. For more information on including related
  data, see http://go.microsoft.com/fwlink/?LinkID=746393.

What am I not understanding?
Model


*

*Driver has many Departures

*Departure has one Driver
Driver:
public class Driver
{
    public int ID { get; set; }
    ...
    public virtual ICollection<Departure> Departures { get; set; }
}

Departure:
public class Departure
{
    public int ID { get; set; }
    public Boolean Acknowledged { get; set; }
    ...
    public int DriverID { get; set; }
    public virtual Driver Driver { get; set; }
}

Using EF Core 2.0 with VS Studio for Mac.

A: You cannot filter departures on the Driver object itself, but you could filter them on the return value:
var driverAndDepartures = await _context.Drivers
  .Select(d => new {
      Driver = d
  ,   UnacknowledgedDepartures = d.Departures.Where(dd => !dd.Acknowledged).ToList()
  })
  .SingleOrDefaultAsync(m => m.ID == id);

Once you get driverAndDepartures back and null-check the result, you can get the driver through driverAndDepartures.Driver and his unacknowledged departures though driverAndDepartures.UnacknowledgedDepartures field.
If you try getting driverAndDepartures.Driver.Departures you would read the whole unfiltered collection of departures.
