I'm trying to filter a collection within an object in Entity Framework. I followed this example, which makes sense.
This is my resulting query:
var filteredClientEmp = context.Clients.Include(x => x.CompanyEmployee)
.Where(c => c.HrPersonId == paId && c.CompanyEmployee.Any(e => e.EmployeeBirthday != null && e.EmpType == 2 &&
e.LeftCompany == null))
.Select(c => new
{
c,
CompanyEmployee =
c.CompanyEmployee.Where(e => e.EmployeeBirthday != null && e.EmpType == 2 &&
e.LeftCompany == null)
})
.ToList()
.Select(pro => pro.c)
.ToList();
return filteredClientEmp;
However, when I inspect the filteredClientEmp object, it contains employee's with no birthday and records where the left company value is not equal to null.
The Client object has a non virtual list of Employee:
public List<Employee> CompanyEmployee { get; set; }
Why is this filtering not working?
contextclean (new)? And what EF version is this?Includeis operational because the fullClientis part of the projection.