带有 2 的 Linq 语句加入了一个 where 并且需要一个计数

Linq statement with 2 joins a where and need a count

这是我的:

var count = (from p in _db.Personen
                        join pc in _db.Postcodes on p.Postcode equals pc.postcode
                        join r in _db.Regios on pc.RegioId equals r.RegioId
                        where (p.Leeftijd >= leeftijdgetal[0] && leeftijd[1] <= p.Leeftijd) &&
                        r.RegioNaam == regio && p.Geslacht == geslacht
                        select new
                        {
                            teller = Where(p => p.Showit == 1).Count()
                        }).Distinct();

计数器出错。 我怎样才能收到该特定地区和特定性别的 2 岁之间的所有人数。

表格如下:

人数:

-PersonId

-姓名 -名 -年龄 -性别 -地址 -邮政编码 -电话 -电子邮件 -密码 -RollId -问卷编号 -状态 -非正式看护人Id -医生ID -eID

邮政编码:

-邮政编码 -乡 -RegionId -邮政编码

地区:

-RegionId -地区名称

在我看来你根本不需要投影

var count = (from p in _db.Personen
             join pc in _db.Postcodes on p.Postcode equals pc.postcode
             join r in _db.Regios on pc.RegioId equals r.RegioId
             where p.Leeftijd >= leeftijdgetal[0] && leeftijd[1] <= p.Leeftijd && 
                   r.RegioNaam == regio && 
                   p.Geslacht == geslacht &&
                   p.Showit == 1
            )
            .Distinct()
            .Count();