2015-11-15 69 views
0

如何删除specefic行我有这样的LINQ到实体:从LINQ结果

 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(), 
             } 

从上面的LINQ我得到这样的结果:

enter image description here

我的问题是如何删除所有行在哪里inspectionFrequency = -1

+3

为什么你不使用'where','where inspectionFreqvency!= -1'?看到这一点:https://msdn.microsoft.com/en-us/library/gg509017.aspx#SimpleWhereClause – AsfK

+0

谢谢,我错过了现在,我意识到,这是愚蠢的问题! – Michael

回答

1

你可以混合和匹配wherelet关键字。它可能是这样的:

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(), 
    }