Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linq AspNetBoilerplate返回所有记录depite where子句_Linq_Aspnetboilerplate_Abp - Fatal编程技术网

Linq AspNetBoilerplate返回所有记录depite where子句

Linq AspNetBoilerplate返回所有记录depite where子句,linq,aspnetboilerplate,abp,Linq,Aspnetboilerplate,Abp,我在使用aspnetboilerplate进行LINQ查询时遇到问题。尽管有where子句,它仍返回所有记录 我想选择具有EnrolResponse.IsComplete=true的所有记录 我有三个实体 public class User : Entity<int>, IFullAudited { public string Email { get; set; } public List<EnrollAttemptRequest> EnrollAtte

我在使用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; }

}
如果将查询分解为IQueryable,但得到相同的结果

可能需要All()而不是Any()

如果使用Any(),则如果至少有1条满足条件,则会获得所有记录。 如果使用All(),则如果所有记录都满足条件,则会得到所有记录

var enroledUsers = await _userRepository.GetAll()
            .Where(x => x.EnrollAttempts.All(y=>y.EnrolResponse.IsComplete == true))
            .Include(x=>x.EnrollAttempts)
            .ThenInclude(x=>x.EnrolResponse)
            .ToListAsync();
也许您需要All()而不是Any()

如果使用Any(),则如果至少有1条满足条件,则会获得所有记录。 如果使用All(),则如果所有记录都满足条件,则会得到所有记录

var enroledUsers = await _userRepository.GetAll()
            .Where(x => x.EnrollAttempts.All(y=>y.EnrolResponse.IsComplete == true))
            .Include(x=>x.EnrollAttempts)
            .ThenInclude(x=>x.EnrolResponse)
            .ToListAsync();

在GitHub上创建一个复制项目,该项目是从中派生出来的。我同意下面给出的答案。where子句只需要一个min of 1记录就可以满足标准,我认为OPCreate在GitHub上创建一个复制项目的目的不是为了满足这个标准。我同意下面给出的答案。where子句只需要一个min of 1记录就可以满足标准——我认为OP并不是有意这样做的