我对使用 aspnetboilerplate 的 LINQ 查询有疑问。尽管有 where 子句,但它会返回所有记录。
我想选择所有具有 EnrolResponse.IsComplete = true 的记录。
我有三个实体
public class User : Entity<int>, IFullAudited
{
public string Email { get; set; }
public List<EnrollAttemptRequest> EnrollAttempts { get; set; }
}
public class EnrollAttemptRequest : Entity<int>
{
public int UserId { get; set; }
public EnrollAttemptResponse EnrolResponse { get; set; }
}
public class EnrollAttemptResponse : Entity<int>, IFullAudited
{
public int EnrollAttemptRequestId { get; set; }
public bool IsComplete { get; set; }
}
以下查询返回所有记录,即使 IsComplete 等于 false。
var enroledUsers = await _userRepository.GetAll()
.Where(x => x.EnrollAttempts.Any(y=>y.EnrolResponse.IsComplete == true))
.Include(x=>x.EnrollAttempts)
.ThenInclude(x=>x.EnrolResponse)
.ToListAsync();
如果将查询分解为 IQueryable 但我得到相同的结果