I am aware of the other similar question at the link below, but those answers do not work as I am db first and the entity framework plus solution is very slow and appears to just get every record and filter it out afterwards. EF: Include with where clause
drivers and passengers are navigational properties on busses. preferredBrands is a List<String>
. So basically what I want is all busses where typeid = 2, all drivers where their preferredbrand is listed in the preferredbrand list, and all passengers. The query below throws exception:
The Include path expression must refer to a navigation property defined on the type. Use dotted paths for reference navigation properties and the Select operator for collection navigation properties.
Parameter name: path
Query:
var result = db.busses.Where(h => h.bussesTypeId.Equals(2))
.Include(h => h.drivers.Where(p => preferredBrands.Contains(p.PreferredBrand)))
.Include(h => h.passengers).ToList();