In the code below, the first LINQ statement grabs all my active customers (c) and includes their Visits. Subsequent lines perform additional filtering but it is not relevant to this question.
On the last line, I’m trying to limit the customers to those customers having a Visit.Id equal to parsedVisitId but cannot get this line to work at all. I can’t put together anything that even compiles. parsedVisitId is an int parsed from a string.
How do I rewrite the last line to return only customers with a visit id equal to parsedVisitId ?
var customers= this.db.Customers.Where(c => c.IsActive).Include(c => c.Visits).AsQueryable();
//
// more filtering stuff happens here...
//
customers= customers.Where(p => p.Visits.Where( v => v.Id == parsedVisitId));
Use Any instead of Where on Visits.I hope the above code line will help.
In your code
customers.Where(…) method expects a lambda expresion that has parameter of type Customer and ReturnType bool but your lambda expression
returns of type
and hence its not working . I wonders how it even compiles.