I have this query, everything works fine except Count, which returns the count for all records in lstISSHDR. I want the COUNT to return the count of field4 in lstISSHDR where lstrej.issuergroupseq = lstisshdr.issuergroupseq
var tmpRejSTM = (from r in lstRej
join l in lstISSHDR on r.IssuerGroupSequence equals l.IssuerGroupSequence
join s in lstSECHDR on r.SecurityGroupSequence equals s.SecurityGroupSequence
where r.Field1 == "INVHDR" && !string.IsNullOrEmpty(l.Field4)
select new { IssuerCode = r.Field4, IssuerName = l.Field6,
SecurityCode = s.Field4, CountofIssuerCode = l.Field4.Count() })
.GroupBy(x => new { x.IssuerCode, x.IssuerName, x.SecurityCode,
x.CountofIssuerCode })
.OrderBy(x => x.Key.IssuerCode).ThenBy(x => x.Key.CountofIssuerCode).ToList();