I have the following model:
public class Car
{
public string Id {get; set;}
public IList<Driver> Drivers {get; set;}
}
public Driver
{
public string Id {get; set;}
public bool IsActive {get; set;}
}
How can I select driver that is active?
var carId = "...";
var activeDriver = await _carCollection.Find(a => a.Id == carId
&& a.Drivers.Any(e=>e.IsActive))
.Project(a=>a.Drivers)
.SingleOrDefaultAsync();
This code returns IList<Driver>, so all items. But I want to retrieve only one Driver that is active.