Michael
Michael

Reputation: 13616

How to remove specefic rows from linq result

I have this Linq to Entity:

        var sitesGrpByClientAndFreq = from cfr in clientFullReview2                                           
                                       group cfr by new { cfr.inspectionFreqvency } into g
                                       select new
                                       {
                                           inspectionFreqvency = g.Key.inspectionFreqvency,
                                           siteCount = g.Select(x => x.siteId).ToArray().Distinct().Count(),
                                           normalSitesCount = g.Where(x => x.isNormal == true).Select(x=>x.isNormal).ToArray().Count(),
                                       }

From the above linq I get this result:

enter image description here

My question is How can I remove all rows where inspectionFrequency = -1?

Upvotes: 0

Views: 47

Answers (1)

Meligy
Meligy

Reputation: 36584

You can mix and match the let keyword with where. It could be something like:

var sitesGrpByClientAndFreq =
  from cfr in clientFullReview2                                           
   group cfr by new { cfr.inspectionFreqvency } into g
   let inspectionFreqvency = g.Key.inspectionFreqvency
   where inspectionFreqvency != -1
   select new
   {
       inspectionFreqvency = inspectionFreqvency,
       siteCount = g.Select(x => x.siteId).ToArray().Distinct().Count(),
       normalSitesCount = g.Where(x => x.isNormal == true).Select(x=>x.isNormal).ToArray().Count(),
   }

Upvotes: 1

Related Questions