C# EF don';t不包括在处删除的字段获得值的行

C# EF don';t不包括在处删除的字段获得值的行,c#,.net,entity-framework,include,where-clause,C#,.net,Entity Framework,Include,Where Clause,我在我的项目中使用实体框架(EF),在每个表中我都得到了列CreatedAt、UpdatedAt、DeletedAt 我的数据模型如下所示: Match包含一个分区、childmatches(比赛模型的副本)、MatchTeam 比赛队可以得分 我创建了一个IQueryable,并在其中包含了所有关系: private IQueryable<Models.Entities.Match> MatchWithEntities(CompetitionContext db) {

我在我的项目中使用实体框架(EF),在每个表中我都得到了列CreatedAt、UpdatedAt、DeletedAt

我的数据模型如下所示:

Match包含一个分区、childmatches(比赛模型的副本)、MatchTeam

比赛队可以得分

我创建了一个IQueryable,并在其中包含了所有关系:

private IQueryable<Models.Entities.Match> MatchWithEntities(CompetitionContext db)
   {
        return db.Matches.Include(x => x.Division)
                          .Include(x => x.ChildMatches)
                          .Include(x => x.ChildMatches.Select(y => y.Division))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.Team)))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.Team.Club)))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.TeamMembers)))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.TeamMembers.Select(a => a.Member))))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.TeamMembers.Select(a => a.Member.Club))))
                          .Include(x => x.ChildMatches.Select(y => y.MatchTeams.Select(z => z.Scores)))
                          .Include(x => x.MatchTeams)
                          .Include(x => x.MatchTeams.Select(y => y.Team))
                          .Include(x => x.MatchTeams.Select(y => y.Team).Select(z => z.Club))
                          .Include(x => x.MatchTeams.Select(y => y.TeamMembers))
                          .Include(x => x.MatchTeams.Select(y => y.TeamMembers.Select(z => z.Member)))
                          .Include(x => x.MatchTeams.Select(y => y.TeamMembers.Select(z => z.Member.Club)))
                          .Include(x => x.MatchTeams.Select(y => y.Scores))
                          .Where(
                                x => !x.DeletedAt.HasValue &&
                                x.MatchTeams.Any(y => !y.Scores.Any() || y.Scores.Any(z => !z.DeletedAt.HasValue))
                          ).OrderBy(x => x.StartAt);
    }
private iQuery可与实体匹配(CompetitionContext db)
{
返回db.Matches.Include(x=>x.Division)
.Include(x=>x.ChildMatches)
.Include(x=>x.ChildMatches.Select(y=>y.Division))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.Team)))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.Team.Club)))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.TeamMembers)))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.TeamMembers.Select(a=>a.Member)))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.TeamMembers.Select(a=>a.Member.Club)))
.Include(x=>x.ChildMatches.Select(y=>y.MatchTeams.Select(z=>z.Scores)))
.包括(x=>x.MatchTeams)
.Include(x=>x.MatchTeams.Select(y=>y.teams))
.包括(x=>x.MatchTeams.Select(y=>y.teams.Select(z=>z.Club))
.Include(x=>x.MatchTeams.Select(y=>y.TeamMembers))
.Include(x=>x.MatchTeams.Select(y=>y.TeamMembers.Select(z=>z.Member)))
.Include(x=>x.MatchTeams.Select(y=>y.TeamMembers.Select(z=>z.Member.Club)))
.包括(x=>x.MatchTeams.选择(y=>y.Scores))
.在哪里(
x=>!x.DeletedAt.HasValue&&
x、 MatchTeams.Any(y=>!y.Scores.Any()| | y.Scores.Any(z=>!z.DeletedAt.HasValue))
).OrderBy(x=>x.StartAt);
}
以下是我获取数据的代码:

 public async Task<Models.Entities.Match> GetAsync(int id)
    {
        using (var db = new CompetitionContext())
        {
            return await MatchWithEntities(db).FirstAsync(x => x.Id == id);
        }
    }
公共异步任务GetAsync(int-id) { 使用(var db=new CompetitionContext()) { 返回wait wait MatchWithEntities(db).FirstAsync(x=>x.Id==Id); } } 在我添加以下句子的地方: x、 MatchTeams.Any(y=>!y.Scores.Any()| | y.Scores.Any(z=>!z.DeletedAt.HasValue))

所以一个matchteam可以有0个分数,也可以有分数,但是我只想要DeletedAt字段没有空值的分数

但我仍然返回带有DeletedAt的行,它得到了一个值


希望有人能帮我解决这个问题。谢谢

尝试z.DeletedAt==null@SaadAlothman谢谢你的回复,我也试过了,但我还是回了那些行。