-3

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();     
4

1 回答 1

0

我只应该改变这个:

CountofIssuerCode = l.Field4.Count()

至:

CountofIssuerCode = lstISSHDR.Where(x=>x.IssuerGroupSequence == l.IssuerGroupSequence).Select(x=>x.Field4).Count()
于 2013-08-26T04:55:12.820 回答